Skip to content

Commit

Permalink
feat: Implement hide author advanced publication settings option - EX…
Browse files Browse the repository at this point in the history
…O-72746 -  Meeds-io/MIPs#161 (#1196)

Implement hide author advanced publication settings option
  • Loading branch information
hakermi authored Nov 4, 2024
1 parent 639c168 commit e83d29a
Show file tree
Hide file tree
Showing 13 changed files with 159 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,8 @@ public class NotePageProperties implements Serializable {

private NoteFeaturedImage featuredImage;

private boolean hideAuthor;

private boolean isDraft;

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class PagePropertiesEntity implements Serializable {
private String summary;

private FeaturedImageEntity featuredImage;

private boolean hideAuthor;

private boolean isDraft;
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static NotePageProperties toNotePageProperties(PagePropertiesEntity pageP
return new NotePageProperties(pagePropertiesEntity.getNoteId(),
pagePropertiesEntity.getSummary(),
toNoteFeaturedImage(pagePropertiesEntity.getFeaturedImage()),
pagePropertiesEntity.isHideAuthor(),
pagePropertiesEntity.isDraft());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ private static void buildPageProperties(Map<String, String> properties, Page not
NoteFeaturedImage noteFeaturedImage = new NoteFeaturedImage();
notePageProperties.setNoteId(Long.parseLong(note.getId()));
notePageProperties.setSummary(properties.get(NoteServiceImpl.SUMMARY_PROP));
notePageProperties.setHideAuthor(Boolean.parseBoolean(properties.getOrDefault(NoteServiceImpl.HIDE_AUTHOR_PROP, "false")));
noteFeaturedImage.setId(Long.valueOf(properties.getOrDefault(NoteServiceImpl.FEATURED_IMAGE_ID, "0")));
noteFeaturedImage.setLastUpdated(Long.valueOf(properties.getOrDefault(NoteServiceImpl.FEATURED_IMAGE_UPDATED_DATE, "0")));
noteFeaturedImage.setAltText(properties.get(NoteServiceImpl.FEATURED_IMAGE_ALT_TEXT));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ public class NoteServiceImpl implements NoteService {

public static final String SUMMARY_PROP = "summary";

public static final String HIDE_AUTHOR_PROP = "hideAuthor";

public static final String FEATURED_IMAGE_ID = "featuredImageId";

public static final String FEATURED_IMAGE_UPDATED_DATE = "featuredImageUpdatedDate";
Expand Down Expand Up @@ -1753,6 +1755,7 @@ public NotePageProperties saveNoteMetadata(NotePageProperties notePageProperties
properties = metadataItem.getProperties();
}
properties.put(SUMMARY_PROP, notePageProperties.getSummary());
properties.put(HIDE_AUTHOR_PROP, String.valueOf(notePageProperties.isHideAuthor()));
if (featuredImageId != null) {
properties.put(FEATURED_IMAGE_ID, String.valueOf(featuredImageId));
properties.put(FEATURED_IMAGE_UPDATED_DATE, String.valueOf(new Date().getTime()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,18 @@ public void testGetDraftsOfWiki() throws Exception {
draftPage.setParentPageId(note2.getId());
noteService.createDraftForExistPage(draftPage, note, null, new Date().getTime(), "root");
assertEquals(2, noteService.getDraftsOfWiki(portalWiki.getOwner(), portalWiki.getType(), portalWiki.getWikiHome().getName()).size());
}

public void testSaveHideAuthorProperty() throws Exception {
Identity user = new Identity("user");
Page note = createTestNoteWithVersionLang("testMetadataHideAuthor", null, user);

this.bindMockedUploadService();

NotePageProperties notePageProperties = createNotePageProperties(Long.parseLong(note.getId()), "alt text", "summary test");
notePageProperties.setHideAuthor(true);
NotePageProperties properties = noteService.saveNoteMetadata(notePageProperties, null, 1L);
assertEquals("summary test", properties.getSummary());
assertTrue(properties.isHideAuthor());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ notes.publication.endTime.label=End time
notes.publication.settings.update.success=Publication settings updated successfully
notes.publication.settings.update.error=Error while updating publication settings
notes.publication.schedule.publish.now.tooltip=By scheduling only a end date you will publish now
notes.publication.advanced.option.label=Advanced options
notes.publication.hide.author.label=Hide author

popup.confirm=Confirm
popup.msg.confirmation=Confirmation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ notes.publication.endTime.label=Heure de fin
notes.publication.settings.update.success=Les paramétres de publication ont été mis \u00E0 jour avec succés
notes.publication.settings.update.error=Erreur lors de la mise \u00E0 jour des paramétres de publication
notes.publication.schedule.publish.now.tooltip=En programmant uniquement une date de fin vous allez publier de suite
notes.publication.advanced.option.label=Options avancées
notes.publication.hide.author.label=Masquer l'auteur

popup.confirm=Confirmer
popup.msg.confirmation=Confirmation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@
}"
ref="scheduleOption"
@updated="updatedScheduleSettings" />
<note-publication-advanced-option
:edit-mode="editMode"
:is-publishing="isPublishing"
:saved-advanced-settings="{
hideAuthor: currentAdvancedSettings?.hideAuthor
}"
ref="advancedOption"
@update="updateAdvancedSettings"/>
</div>
</v-scroll-y-transition>
</div>
Expand Down Expand Up @@ -208,8 +216,10 @@ export default {
post: true
},
scheduleSettings: {},
advancedSettings: {},
currentPublicationSettings: {},
currentScheduleSettings: {}
currentScheduleSettings: {},
currentAdvancedSettings: {}
};
},
props: {
Expand Down Expand Up @@ -287,10 +297,16 @@ export default {
}
},
methods: {
updateAdvancedSettings(settings) {
this.advancedSettings = structuredClone(settings);
this.publicationSettings.advancedSettings = this.advancedSettings;
this.noteObject.properties.hideAuthor = this.advancedSettings?.hideAuthor;
},
updatedPublicationSettings(settings) {
this.publicationSettings = structuredClone({
post: this.publicationSettings.post,
scheduleSettings: this.publicationSettings.scheduleSettings
scheduleSettings: this.publicationSettings.scheduleSettings,
advancedSettings: this.publicationSettings.advancedSettings
});
this.publicationSettings.publish = settings?.publish;
this.publicationSettings.selectedTargets = settings?.selectedTargets;
Expand Down Expand Up @@ -321,26 +337,20 @@ export default {
open(noteObject) {
this.noteObject = noteObject;
if (this.editMode) {
this.publicationSettings.post = this.noteObject?.activityPosted;

this.scheduleSettings.schedule = !!this.noteObject?.schedulePostDate || !!this.noteObject?.scheduleUnpublishDate;
this.scheduleSettings.editScheduleAction = this.scheduleSettings.schedule && 'schedule' || null;
this.scheduleSettings.postDate = this.noteObject?.schedulePostDate;
this.scheduleSettings.unpublishDate = this.noteObject?.scheduleUnpublishDate;
this.publicationSettings.scheduleSettings = this.scheduleSettings;

this.publicationSettings.publish = this.noteObject?.published;
this.publicationSettings.selectedTargets = this.noteObject?.targets;
this.publicationSettings.selectedAudience = this.noteObject?.audience;
this.cloneScheduleSettings();
this.cloneAdvancedSettings();
this.clonePublicationSettings();
}
this.currentScheduleSettings = structuredClone(this.scheduleSettings);
this.currentAdvancedSettings = structuredClone(this.advancedSettings);
this.currentPublicationSettings = structuredClone(this.publicationSettings);
this.cloneProperties();
this.$refs.publicationDrawer.open();
this.toggleExpand();
setTimeout(() => {
this.$refs?.publishOption?.initSettings();
this.$refs?.scheduleOption?.initSettings();
this.$refs?.advancedOption?.initSettings();
}, 200);
this.$refs.propertiesForm?.initProperties();
},
Expand All @@ -351,6 +361,23 @@ export default {
}, 50);
}
},
cloneAdvancedSettings() {
this.advancedSettings.hideAuthor = this.noteObject?.properties?.hideAuthor;
},
clonePublicationSettings() {
this.publicationSettings.post = this.noteObject?.activityPosted;
this.publicationSettings.scheduleSettings = this.scheduleSettings;
this.publicationSettings.advancedSettings = this.advancedSettings;
this.publicationSettings.publish = this.noteObject?.published;
this.publicationSettings.selectedTargets = this.noteObject?.targets;
this.publicationSettings.selectedAudience = this.noteObject?.audience;
},
cloneScheduleSettings() {
this.scheduleSettings.schedule = !!this.noteObject?.schedulePostDate || !!this.noteObject?.scheduleUnpublishDate;
this.scheduleSettings.editScheduleAction = this.scheduleSettings.schedule && 'schedule' || null;
this.scheduleSettings.postDate = this.noteObject?.schedulePostDate;
this.scheduleSettings.unpublishDate = this.noteObject?.scheduleUnpublishDate;
},
cloneProperties() {
this.currentNoteProperties = structuredClone(
this.noteObject?.id &&
Expand All @@ -368,6 +395,7 @@ export default {
cancelChanges() {
this.$refs?.publishOption?.cancelChanges();
this.$refs?.scheduleOption?.cancelChanges();
this.$refs?.advancedOption?.cancelChanges();
},
reset() {
setTimeout(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<!--
This file is part of the Meeds project (https://meeds.io/).

Copyright (C) 2024 Meeds Association contact@meeds.io

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-->

<template>
<div class="mt-8">
<p class="mb-0 text-truncate text-color font-weight-bold">
{{ $t('notes.publication.advanced.option.label') }}
</p>
<div class="d-flex mt-4">
<v-switch
v-model="hideAuthor"
:disabled="isPublishing"
:aria-label="$t('notes.publication.hide.author.label')"
:ripple="false"
color="primary"
class="mt-n1 me-1" />
<p class="mb-5">
{{ $t('notes.publication.hide.author.label') }}
</p>
</div>
</div>
</template>

<script>
export default {
data() {
return {
hideAuthor: false
};
},
props: {
isPublishing: {
type: Boolean,
default: false
},
savedAdvancedSettings: {
type: Object,
default: null
},
editMode: {
type: Boolean,
default: false
}
},
watch: {
hideAuthor() {
this.emitAdvancedSettingsUpdate();
}
},
created() {
this.initSettings();
},
methods: {
emitAdvancedSettingsUpdate() {
this.$emit('update', {
hideAuthor: this.hideAuthor
});
},
initSettings() {
if (!this.editMode) {
return;
}
this.hideAuthor = this.savedAdvancedSettings?.hideAuthor;
},
cancelChanges() {
this.initSettings();
}
}
};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@
:ripple="false"
color="primary"
class="mt-n1 me-1" />
<p class="mb-5">
<p class="mb-0">
{{ $t('notes.publication.schedule.label') }}
</p>
</div>
<div
v-if="schedule"
:class="{'d-flex': !showStartDate && expanded}"
class="width-fit-content">
class="width-fit-content mt-5">
<div
:class="{'d-flex': !publish || expanded}"
class="justify-start">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import NotePublishOption from './components/publish-option/NotePublishOption.vue
import NotePublicationTargetDrawer from './components/publish-option/NotePublicationTargetDrawer.vue';
import NotePublicationTargetList from './components/publish-option/NotePublicationTargetList.vue';
import NoteScheduleOption from './components/schedule-option/NoteScheduleOption.vue';
import NotePublicationAdvancedOption from './components/advanced-option/NotePublicationAdvancedOption.vue';

const components = {
'note-publication-drawer': NotePublicationDrawer,
'note-metadata-properties-form': NoteMetadataPropertiesForm,
'note-publish-option': NotePublishOption,
'note-publication-target-drawer': NotePublicationTargetDrawer,
'note-publication-target-list': NotePublicationTargetList,
'note-schedule-option': NoteScheduleOption
'note-schedule-option': NoteScheduleOption,
'note-publication-advanced-option': NotePublicationAdvancedOption
};

for (const key in components) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ export default {
const properties = {
noteId: this.noteObject?.id,
summary: this.summaryContent,
hideAuthor: this.noteObject?.properties?.hideAuthor,
featuredImage: {
id: savedFeaturedImageId,
uploadId: this.uploadId,
Expand Down

0 comments on commit e83d29a

Please sign in to comment.