Skip to content

Commit

Permalink
feat: Add a target from the drawer News list - EXO-65536 - Meeds-io/M…
Browse files Browse the repository at this point in the history
  • Loading branch information
GouadriaHanen authored and exo-swf committed Aug 9, 2023
1 parent 86f438c commit c90a091
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,5 @@ news.latest.openSettings=Open settings

# For news page template
UIWizardPageSelectLayoutForm.label.newsPage.newsLayout=News

news.list.settings.drawer.createNewTarget=Create new target
33 changes: 33 additions & 0 deletions webapp/src/main/webapp/WEB-INF/gatein-resources.xml
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@
<minify>false</minify>
<path>/js/newsListView.bundle.js</path>
</script>
<depends>
<module>newsTargetsManagement</module>
</depends>
<depends>
<module>vue</module>
</depends>
Expand Down Expand Up @@ -282,6 +285,36 @@
</module>
</portlet>

<module>
<name>newsTargetsManagement</name>
<script>
<minify>false</minify>
<path>/js/newsPublishTargetsManagement.bundle.js</path>
</script>
<depends>
<module>vue</module>
</depends>
<depends>
<module>vuetify</module>
</depends>
<depends>
<module>eXoVueI18n</module>
</depends>
<depends>
<module>jquery</module>
<as>$</as>
</depends>
<depends>
<module>extensionRegistry</module>
</depends>
<depends>
<module>commonVueComponents</module>
</depends>
<depends>
<module>newsSnackbarComponent</module>
</depends>
</module>

<module>
<name>newsDetails</name>
<script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
</v-card-text>
</v-card>
<news-settings-drawer v-if="canPublishNews" />
<news-publish-targets-management-drawer v-if="canPublishNews" />
</v-app>
</template>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
</template>
</v-select>
</div>
<div class="d-flex flex-row clickable text-decoration-underline">
<a @click="createNewTarget"> {{ $t('news.list.settings.drawer.createNewTarget') }} </a>
</div>
<div v-if="newsTargets.length === 0" class="d-flex flex-row grey--text">
<i class="fas fa-exclamation-triangle mt-3"></i>
<span class="mx-2"> {{ $t('news.composer.stepper.selectedTarget.noTargetAllowed') }}</span>
Expand Down Expand Up @@ -263,6 +266,16 @@ export default {
this.init();
setTimeout(() => this.open(), 100);
});
this.$root.$on('new-news-target-created', (target) => {
const newTarget = {
name: target.name,
label: target?.properties?.label && target.properties.label.length > 35 ? target.properties.label.substring(0, 35).concat('...'): target.properties.label,
toolTipInfo: target?.properties?.label,
description: target?.properties?.description
};
this.newsTargets.push(newTarget);
this.newsTarget = newTarget.name;
});
this.$newsServices.canPublishNews().then(canPublishNews => {
this.saveSettingsURL = canPublishNews ? this.$root.saveSettingsURL : null;
});
Expand Down Expand Up @@ -450,6 +463,9 @@ export default {
switchSettingsDrawer() {
this.showAdvancedSettings = !this.showAdvancedSettings;
this.reset();
},
createNewTarget() {
this.$root.$emit('open-news-publish-targets-management-drawer');
}
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ export default {
}
this.saveMode = 'edit';
});
this.$root.$on('open-news-publish-targets-management-drawer', () => { this.open(); });
},
methods: {
removePermission(permission) {
Expand Down Expand Up @@ -287,12 +288,14 @@ export default {
};
this.sameTargetError = false;
this.$newsTargetingService.createTarget(target)
.then((resp) => {
if (resp && resp === 200) {
this.$emit('news-target-saved');
this.reset();
this.closeDrawer();
} else if (resp && resp === 409) {
.then((createdTarget) => {
this.$emit('news-target-saved');
this.$root.$emit('new-news-target-created', createdTarget);
this.reset();
this.closeDrawer();
})
.catch((resp) => {
if (resp.message && resp.message === 409) {
this.sameTargetError = true;
this.disabled = true;
this.saving = false;
Expand Down
8 changes: 3 additions & 5 deletions webapp/src/main/webapp/services/newsTargetingService.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,9 @@ export function createTarget(target) {
body: JSON.stringify(target),
}).then((resp) => {
if (resp && resp.ok) {
return resp.status;
} else if ( resp.status === 409) {
return resp.status;
} else {
throw new Error('Error when creating news target');
return resp.json();
} else {
throw new Error(resp.status);
}
});
}
Expand Down

0 comments on commit c90a091

Please sign in to comment.