From e179ec485abd601ddd228bc68ea47d31002460c5 Mon Sep 17 00:00:00 2001 From: Francesco Lo Faro Date: Tue, 5 Sep 2023 17:07:00 +0200 Subject: [PATCH 01/10] form improvements --- src/components/ArticleListItem.vue | 4 +- src/views/ArticlesView.vue | 103 +++++++++++++++-------------- 2 files changed, 55 insertions(+), 52 deletions(-) diff --git a/src/components/ArticleListItem.vue b/src/components/ArticleListItem.vue index 6467167..e8dc22e 100644 --- a/src/components/ArticleListItem.vue +++ b/src/components/ArticleListItem.vue @@ -40,8 +40,8 @@ library.add(faCalendar, faLocationDot, faTrashCan, faEye); {{ content.it.title || content.en.title }} -
- {{ content.it.subtitle || content.en.subtitle }} +
+ {{ content.it.subtitle}}
Nessun sottotitolo
diff --git a/src/views/ArticlesView.vue b/src/views/ArticlesView.vue index fb1a004..f51b7dc 100644 --- a/src/views/ArticlesView.vue +++ b/src/views/ArticlesView.vue @@ -29,15 +29,16 @@ >
-
- +
-
- +
+
- L'oggetto non può essere vuoto. + Il titolo non può essere vuoto.
-
- +
+

Guida al Markdown

-
- +
+
Deve essere un URL valido.
@@ -124,14 +129,15 @@
-
- +
+
-
- +
+
@@ -321,7 +328,8 @@ export default { deletedPageOffset: 0, articlecontent: {ita: {}, eng: {}}, cherryInstance: null, - selectedLanguage: 'ita' + selectedLanguage: 'ita', + requestbody: {} }; }, mounted() { @@ -475,19 +483,16 @@ export default { validBody = this.cherryInstance.getMarkdown() != ""; // Check if the image url is valid - var thumbnail = "", - datetime; + var datetime; if ( - $("#copertinaArticolo").val() != "" && - !$("#copertinaArticolo") - .val() + this.requestbody.image != "" && + !this.requestbody.image .match(/^(http|https):\/\/[^ "]+$/) ) { $("#copertinaArticolo").addClass("is-invalid"); validImageUrl = false; } else { $("#copertinaArticolo").removeClass("is-invalid"); - thumbnail = $("#copertinaArticolo").val(); validImageUrl = true; } @@ -503,8 +508,7 @@ export default { this.articlecontent[this.selectedLanguage].subtitle = $("#sottotitoloArticolo").val() || null; this.articlecontent[this.selectedLanguage].content = this.cherryInstance.getMarkdown(); - var data = { - content: [ + this.requestbody.content = [ { title: this.articlecontent.ita.title, subtitle: this.articlecontent.ita.subtitle, @@ -515,38 +519,37 @@ export default { subtitle: this.articlecontent.eng.subtitle, content: this.articlecontent.eng.content, } - ], - author_id: parseInt($("#selectmittente").val()), - tag: $("#selectcategoria").val(), - platforms: selectedplats, - }; + ], + //author_id: parseInt($("#selectmittente").val()), + //tag: $("#selectcategoria").val(), + this.requestbody.platforms = selectedplats; if (this.articlecontent.eng.title == null) { - data.content.pop(); + this.requestbody.content.pop(); } datetime = window.extraorario.dates; if (datetime != null) { - data["target_time"] = datetime.picked[0]; + this.requestbody.target_time = datetime.picked[0]; } if (marker != null) { - data["latitude"] = marker.getLatLng().lat; - data["longitude"] = marker.getLatLng().lng; + this.requestbody.latitude = marker.getLatLng().lat; + this.requestbody.longitude = marker.getLatLng().lng; } - if (thumbnail != "") { - data["image"] = thumbnail; + if (this.requestbody.image == "") { + this.requestbody.image = null; } var delayedrelease = window.datetimepickerdelay.dates; if (delayedrelease.picked.length > 0) { - data["hidden_until"] = delayedrelease.picked[0]; + this.requestbody.hidden_until = delayedrelease.picked[0]; } axios - .post(API_BASE_URL + "/articles", data, { + .post(API_BASE_URL + "/articles", this.requestbody, { headers: { "Content-Type": "application/json", Authorization: @@ -727,20 +730,20 @@ export default { // If the button clicked is the english one, save the italian content and load the english one if (el.id == "btnradioita") { this.articlecontent.eng.title = $("#titoloArticolo").val(); - this.articlecontent.eng.subtitle = $("#sottotitoloArticolo").val(); + this.articlecontent.eng.subtitle = $("#sottArticolo").val(); this.articlecontent.eng.content = this.cherryInstance.getMarkdown(); $("#titoloArticolo").val(this.articlecontent.ita.title); - $("#sottotitoloArticolo").val(this.articlecontent.ita.subtitle); + $("#sottArticolo").val(this.articlecontent.ita.subtitle); this.cherryInstance = this.startEditor(this.articlecontent.ita.content || ""); } else { this.articlecontent.ita.title = $("#titoloArticolo").val(); - this.articlecontent.ita.subtitle = $("#sottotitoloArticolo").val(); + this.articlecontent.ita.subtitle = $("#sottArticolo").val(); this.articlecontent.ita.content = this.cherryInstance.getMarkdown(); $("#titoloArticolo").val(this.articlecontent.eng.title); - $("#sottotitoloArticolo").val(this.articlecontent.eng.subtitle); + $("#sottArticolo").val(this.articlecontent.eng.subtitle); this.cherryInstance = this.startEditor(this.articlecontent.eng.content || ""); ///this.startEditor(this.cherryInstance, this.articlecontent.eng.content || "# hello"); } From bd967779a4ac8cb8323e3f83eca9cd265c195eff Mon Sep 17 00:00:00 2001 From: Francesco Lo Faro Date: Sun, 17 Sep 2023 21:31:40 +0200 Subject: [PATCH 02/10] fixes --- src/App.vue | 6 +- src/assets/styles/main.css | 4 + src/components/ArticleListItem.vue | 2 +- src/views/ArticlesView.vue | 179 ++++++++++++++++++----------- src/views/PermissionsView.vue | 34 +++--- src/views/WelcomeView.vue | 17 ++- 6 files changed, 157 insertions(+), 85 deletions(-) diff --git a/src/App.vue b/src/App.vue index 947351b..75dec2f 100644 --- a/src/App.vue +++ b/src/App.vue @@ -30,7 +30,11 @@ const { loggedIn } = storeToRefs(store); class="navbar navbar-expand-md navbar-dark bg-dark sticky-top" > - PoliFemo Dashboard + + PoliFemo Dashboard
@@ -114,8 +114,8 @@ export default { headers: { "Content-Type": "application/json", Authorization: - "Bearer " + localStorage.getItem("polifemo_access_token"), - }, + "Bearer " + localStorage.getItem("polifemo_access_token") + } }) .then(() => { this.emitter.emit("article-deleted", this.id); @@ -137,7 +137,7 @@ export default { btn.classList.remove("btn-list-item-action"); btn.innerHTML = "Sicuro?"; } - }, - }, + } + } }; diff --git a/src/components/HelloWorld.vue b/src/components/HelloWorld.vue index e4d26e1..46cec22 100644 --- a/src/components/HelloWorld.vue +++ b/src/components/HelloWorld.vue @@ -2,8 +2,8 @@ defineProps({ msg: { type: String, - required: true, - }, + required: true + } }); diff --git a/src/components/LoginButton.vue b/src/components/LoginButton.vue index 72a6dda..17657d8 100644 --- a/src/components/LoginButton.vue +++ b/src/components/LoginButton.vue @@ -2,17 +2,17 @@ defineProps({ loginDestination: { type: String, - required: true, + required: true }, loginText: { type: String, - required: true, + required: true }, buttonType: { type: String, required: false, - default: "primary", - }, + default: "primary" + } }); @@ -90,7 +90,7 @@ export default { ); break; } - }, - }, + } + } }; diff --git a/src/components/PermissionListItem.vue b/src/components/PermissionListItem.vue index 0d38af0..5505a66 100644 --- a/src/components/PermissionListItem.vue +++ b/src/components/PermissionListItem.vue @@ -3,7 +3,7 @@ import { faUser, faNewspaper, faTag, - faXmark, + faXmark } from "@fortawesome/free-solid-svg-icons"; import { library } from "@fortawesome/fontawesome-svg-core"; import axios from "axios"; @@ -14,16 +14,16 @@ import { showToast } from "@/plugins/ToastManager"; defineProps({ userid: { type: String, - required: true, + required: true }, objectid: { type: Number, - required: false, + required: false }, grant: { type: String, - required: true, - }, + required: true + } }); library.add(faUser, faNewspaper, faTag, faXmark); @@ -70,7 +70,7 @@ export default { var data = { grant: this.grant, - object_id: this.objectid ?? null, + object_id: this.objectid ?? null }; axios @@ -78,9 +78,9 @@ export default { headers: { "Content-Type": "application/json", Authorization: - "Bearer " + localStorage.getItem("polifemo_access_token"), + "Bearer " + localStorage.getItem("polifemo_access_token") }, - data: data, + data: data }) .then(() => { this.emitter.emit("permission-deleted", data); @@ -107,7 +107,7 @@ export default { btn.classList.remove("btn-list-item-action"); btn.innerHTML = "Sicuro?"; } - }, - }, + } + } }; diff --git a/src/components/barItems/BarItem.vue b/src/components/barItems/BarItem.vue index d050a86..fa016ec 100644 --- a/src/components/barItems/BarItem.vue +++ b/src/components/barItems/BarItem.vue @@ -3,7 +3,7 @@ import { faMoon, faSun, faNewspaper, - faTag, + faTag } from "@fortawesome/free-solid-svg-icons"; import { library } from "@fortawesome/fontawesome-svg-core"; library.add(faMoon, faSun, faNewspaper, faTag); @@ -11,20 +11,20 @@ library.add(faMoon, faSun, faNewspaper, faTag); defineProps({ dest: { type: String, - required: true, + required: true }, title: { type: String, - required: true, + required: true }, icon: { type: String, - required: true, + required: true }, permission: { type: String, - required: true, - }, + required: true + } }); @@ -64,7 +64,7 @@ export default { } }); if (f > 0) return true; - }, - }, + } + } }; diff --git a/src/components/barItems/DarkModeBarItem.vue b/src/components/barItems/DarkModeBarItem.vue index 033c5fe..87d9c8a 100644 --- a/src/components/barItems/DarkModeBarItem.vue +++ b/src/components/barItems/DarkModeBarItem.vue @@ -13,7 +13,7 @@ export default { computed: { darkMode: function () { return localStorage.getItem("bs.prefers-color-scheme") === "dark"; - }, + } }, mounted() { @@ -37,7 +37,7 @@ export default { document.getElementById("darkmode-icon").classList.remove("fa-sun"); document.getElementById("darkmode-icon").classList.add("fa-moon"); } - }, - }, + } + } }; diff --git a/src/components/barItems/LogoutBarItem.vue b/src/components/barItems/LogoutBarItem.vue index 7e7c98f..135d2c9 100644 --- a/src/components/barItems/LogoutBarItem.vue +++ b/src/components/barItems/LogoutBarItem.vue @@ -14,7 +14,7 @@ export default { localStorage.removeItem("polifemo_access_token"); localStorage.removeItem("polifemo_refresh_token"); window.location.href = window.location.href.split("/")[0]; - }, - }, + } + } }; diff --git a/src/main.js b/src/main.js index 8aae5eb..63f2e47 100644 --- a/src/main.js +++ b/src/main.js @@ -18,8 +18,8 @@ function bootApp() { * You can pass default config to vue app like router , ... (optional) */ configs: { - router, - }, + router + } }) .use(createPinia()); diff --git a/src/plugins/AuthUtils.js b/src/plugins/AuthUtils.js index 9db1e08..3efe34b 100644 --- a/src/plugins/AuthUtils.js +++ b/src/plugins/AuthUtils.js @@ -9,8 +9,8 @@ export const refreshAuthLogic = async (failedRequest) => { loggers.mainLogger.info("Auth", "Invalid token, refreshing..."); const tokenRefreshResponse = await axios.get(API_BASE_URL + "/auth/refresh", { headers: { - Token: localStorage.getItem("polifemo_refresh_token"), - }, + Token: localStorage.getItem("polifemo_refresh_token") + } }); if (tokenRefreshResponse.status == 200) { loggers.mainLogger.info("Auth", "Token refreshed successfully"); @@ -41,8 +41,8 @@ export const refreshPermissions = async (skipRequest) => .get(API_BASE_URL + "/accounts/me", { headers: { Authorization: - "Bearer " + localStorage.getItem("polifemo_access_token"), - }, + "Bearer " + localStorage.getItem("polifemo_access_token") + } }) .then((response) => { store.userid = response.data.id; diff --git a/src/plugins/ConsoleLoggers.js b/src/plugins/ConsoleLoggers.js index bf25caa..7a96c14 100644 --- a/src/plugins/ConsoleLoggers.js +++ b/src/plugins/ConsoleLoggers.js @@ -13,6 +13,6 @@ export default { "color: #f50000; font-weight: bold", message ); - }, - }, + } + } }; diff --git a/src/plugins/VueModular.js b/src/plugins/VueModular.js index 542a1ff..da37c5b 100644 --- a/src/plugins/VueModular.js +++ b/src/plugins/VueModular.js @@ -3,7 +3,7 @@ import { createRouter, createWebHistory } from "vue-router"; const createRouterInstance = () => { return createRouter({ history: createWebHistory(import.meta.env.BASE_URL), - routes: [], + routes: [] }); }; @@ -13,5 +13,5 @@ export default { const { router = createRouterInstance() } = options.configs; modules.forEach((module) => module.install({ router })); app.use(router); - }, + } }; diff --git a/src/router/index.js b/src/router/index.js index caf2b36..57fae5c 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -6,7 +6,7 @@ const router = createRouter({ { path: "/", name: "home", - component: WelcomeView, + component: WelcomeView }, { path: "/articoli", @@ -14,14 +14,14 @@ const router = createRouter({ // route level code-splitting // this generates a separate chunk (About.[hash].js) for this route // which is lazy-loaded when the route is visited. - component: () => import("@/views/ArticlesView.vue"), + component: () => import("@/views/ArticlesView.vue") }, { path: "/permessi", name: "permessi", - component: () => import("@/views/PermissionsView.vue"), - }, - ], + component: () => import("@/views/PermissionsView.vue") + } + ] }); const validRoutes = ["/", "/articoli", "/permessi"]; diff --git a/src/stores/autofill.json b/src/stores/autofill.json index 3acf5c7..d88072a 100644 --- a/src/stores/autofill.json +++ b/src/stores/autofill.json @@ -1,7 +1,3 @@ { - "authors": [ - "", - "Politecnico di Milano", - "PoliNetwork" - ] -} \ No newline at end of file + "authors": ["", "Politecnico di Milano", "PoliNetwork"] +} diff --git a/src/stores/polifemo.js b/src/stores/polifemo.js index 02541ed..8eb6c88 100644 --- a/src/stores/polifemo.js +++ b/src/stores/polifemo.js @@ -7,6 +7,6 @@ export const usePolifemoStore = defineStore({ loggedIn: false, darkModeEnabled: false, perms: [], - authorizedauthors: [], - }), + authorizedauthors: [] + }) }); diff --git a/src/views/ArticlesView.vue b/src/views/ArticlesView.vue index 619bf32..f5843a6 100644 --- a/src/views/ArticlesView.vue +++ b/src/views/ArticlesView.vue @@ -36,9 +36,7 @@ aria-label="Seleziona mittente" v-model="requestbody.author_id" /> - +

- +
0) { this.requestbody.hidden_until = delayedrelease.picked[0]; } - + axios .post(API_BASE_URL + "/articles", this.requestbody, { headers: { "Content-Type": "application/json", Authorization: - "Bearer " + localStorage.getItem("polifemo_access_token"), - }, + "Bearer " + localStorage.getItem("polifemo_access_token") + } }) // If the request is successful, show a success toast, close and reset the form .then(function (response) { showToast("Articolo creato con successo", "success"); var myCollapse = document.getElementById("collapseOne"); new bootstrap.Collapse(myCollapse, { - toggle: true, + toggle: true }); form.classList.remove("was-validated"); loggers.mainLogger.info( @@ -664,7 +662,7 @@ export default { document.getElementById("extramappa").style.height = "400px"; mappa = L.map("extramappa").setView([45.47812, 9.22818], 18); L.tileLayer("https://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}", { - maxZoom: 20, + maxZoom: 20 }).addTo(mappa); mappa.on("click", function (e) { @@ -678,8 +676,8 @@ export default { document.getElementById("extraorario"), { display: { - theme: store.darkModeEnabled ? "dark" : "light", // Display the correct theme based on the stored preference - }, + theme: store.darkModeEnabled ? "dark" : "light" // Display the correct theme based on the stored preference + } } ); @@ -776,8 +774,9 @@ export default { $("#titoloArticolo").val(this.articlecontent.ita.title); $("#sottArticolo").val(this.articlecontent.ita.subtitle); - this.cherryInstance = this.startEditor(this.articlecontent.ita.content || ""); - + this.cherryInstance = this.startEditor( + this.articlecontent.ita.content || "" + ); } else { this.articlecontent.ita.title = $("#titoloArticolo").val(); this.articlecontent.ita.subtitle = $("#sottArticolo").val(); @@ -785,7 +784,9 @@ export default { $("#titoloArticolo").val(this.articlecontent.eng.title); $("#sottArticolo").val(this.articlecontent.eng.subtitle); - this.cherryInstance = this.startEditor(this.articlecontent.eng.content || ""); + this.cherryInstance = this.startEditor( + this.articlecontent.eng.content || "" + ); ///this.startEditor(this.cherryInstance, this.articlecontent.eng.content || "# hello"); } }, @@ -796,7 +797,7 @@ export default { $(editor).remove(); //$("#editor-wrapper").empty(); $("#editor-wrapper").append( - "
", + "
" ); return new Cherry({ @@ -818,7 +819,7 @@ export default { "checklist", "list", "link", - "table", + "table" ], bubble: [ "bold", @@ -827,13 +828,13 @@ export default { "strikethrough", "sub", "sup", - "quote", + "quote" ], float: [] }, - locale: 'en_US' + locale: "en_US" }); } - }, + } }; diff --git a/src/views/PermissionsView.vue b/src/views/PermissionsView.vue index 7d42ba4..5b47980 100644 --- a/src/views/PermissionsView.vue +++ b/src/views/PermissionsView.vue @@ -95,7 +95,7 @@ import { faCircleInfo, faUser, - faPlus, + faPlus } from "@fortawesome/free-solid-svg-icons"; import { library } from "@fortawesome/fontawesome-svg-core"; import loggers from "@/plugins/ConsoleLoggers"; @@ -137,7 +137,7 @@ export default { this.emitter.on("permission-deleted", (removed) => { this.tempPermList = this.tempPermList.filter( (perm) => - perm.grant !== removed.grant && perm.object_id !== removed.object_id, + perm.grant !== removed.grant && perm.object_id !== removed.object_id ); }); }, @@ -151,7 +151,7 @@ export default { { headers: { Authorization: - "Bearer " + localStorage.getItem("polifemo_access_token"), + "Bearer " + localStorage.getItem("polifemo_access_token") } } ) @@ -171,11 +171,11 @@ export default { addPermission() { //place spinner inside button $("#addpermbutton").html( - '', + '' ); const perm = $("#added-perm").val(); var data = { - grant: perm, + grant: perm }; if (this.autofill.hasOwnProperty(perm)) { var index = 0; @@ -194,8 +194,8 @@ export default { { headers: { Authorization: - "Bearer " + localStorage.getItem("polifemo_access_token"), - }, + "Bearer " + localStorage.getItem("polifemo_access_token") + } } ) .then((response) => { @@ -211,7 +211,7 @@ export default { .finally(() => { $("#addpermbutton").html(''); }); - }, - }, + } + } }; diff --git a/src/views/WelcomeView.vue b/src/views/WelcomeView.vue index 5758c1e..d934975 100644 --- a/src/views/WelcomeView.vue +++ b/src/views/WelcomeView.vue @@ -51,7 +51,7 @@ import { faCopy, faCheck } from "@fortawesome/free-solid-svg-icons"; import { library } from "@fortawesome/fontawesome-svg-core"; export default { components: { - LoginButton, + LoginButton }, setup() { const store = usePolifemoStore(); @@ -60,7 +60,7 @@ export default { return { loggedIn, perms, - userid, + userid }; }, methods: { @@ -77,5 +77,5 @@ export default { navigator.clipboard.writeText(this.userid); } } -} +}; diff --git a/vite.config.js b/vite.config.js index 0fbfa5a..7979718 100644 --- a/vite.config.js +++ b/vite.config.js @@ -8,7 +8,7 @@ export default defineConfig({ base: "/", resolve: { alias: { - "@": fileURLToPath(new URL("./src", import.meta.url)), - }, - }, + "@": fileURLToPath(new URL("./src", import.meta.url)) + } + } }); From 03248d9e4e260c1b1e730927e31da7d1df9b99c7 Mon Sep 17 00:00:00 2001 From: Francesco Lo Faro Date: Sun, 17 Sep 2023 22:53:54 +0200 Subject: [PATCH 05/10] . --- src/views/ArticlesView.vue | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/views/ArticlesView.vue b/src/views/ArticlesView.vue index f5843a6..f41f7ab 100644 --- a/src/views/ArticlesView.vue +++ b/src/views/ArticlesView.vue @@ -166,7 +166,9 @@ v-model="requestbody.tag" required /> - +

From 5054995689d58b657c4e2cc14f3c2ef7f16400c7 Mon Sep 17 00:00:00 2001 From: Francesco Lo Faro Date: Mon, 18 Sep 2023 20:14:49 +0200 Subject: [PATCH 06/10] standalone search form --- src/components/ArticleListItem.vue | 9 +- src/components/ArticlesSearchForm.vue | 179 ++++++++++++++++++++++++++ src/components/PermissionListItem.vue | 4 +- src/stores/strings.json | 0 src/views/ArticlesView.vue | 157 +--------------------- 5 files changed, 192 insertions(+), 157 deletions(-) create mode 100644 src/components/ArticlesSearchForm.vue create mode 100644 src/stores/strings.json diff --git a/src/components/ArticleListItem.vue b/src/components/ArticleListItem.vue index 63986e3..648a4df 100644 --- a/src/components/ArticleListItem.vue +++ b/src/components/ArticleListItem.vue @@ -24,6 +24,10 @@ defineProps({ content: { type: Object, required: true + }, + buttons: { + type: String, + required: true } }); @@ -51,6 +55,7 @@ library.add(faCalendar, faLocationDot, faTrashCan, faEye); type="button" id="btn-preview" v-on:click="preview" + v-if="displayedButtons.includes('preview')" class="btn no-border btn-info rounded-start h-100 btn-list-item-action" > @@ -59,6 +64,7 @@ library.add(faCalendar, faLocationDot, faTrashCan, faEye); type="button" v-on:click="remove" id="btn-delete" + v-if="displayedButtons.includes('delete')" class="btn no-border btn-danger rounded-end h-100 btn-list-item-action" > @@ -76,7 +82,8 @@ export default { data() { return { cherryEditor: null, - previewBox: null + previewBox: null, + displayedButtons: this.buttons.split(",") || [] }; }, mounted() { diff --git a/src/components/ArticlesSearchForm.vue b/src/components/ArticlesSearchForm.vue new file mode 100644 index 0000000..7c50ae6 --- /dev/null +++ b/src/components/ArticlesSearchForm.vue @@ -0,0 +1,179 @@ + + + diff --git a/src/components/PermissionListItem.vue b/src/components/PermissionListItem.vue index 5505a66..891cb03 100644 --- a/src/components/PermissionListItem.vue +++ b/src/components/PermissionListItem.vue @@ -35,9 +35,9 @@ library.add(faUser, faNewspaper, faTag, faXmark);

-   {{ grant }} +  {{ grant }} -   {{ grant }} • {{ autofill[grant][objectid] }} +  {{ grant }} • {{ autofill[grant][objectid] }}
diff --git a/src/stores/strings.json b/src/stores/strings.json new file mode 100644 index 0000000..e69de29 diff --git a/src/views/ArticlesView.vue b/src/views/ArticlesView.vue index f41f7ab..729a615 100644 --- a/src/views/ArticlesView.vue +++ b/src/views/ArticlesView.vue @@ -262,51 +262,7 @@ aria-labelledby="headingTwo" data-bs-parent="#accordionAggiungi" > -
-
- - -
-
-
- Loading... -
-
-
- -
- -
-
-
+
@@ -339,7 +295,7 @@ import axios from "axios"; import Cherry from "cherry-markdown/dist/cherry-markdown.core"; import { API_BASE_URL, checkPagePermission } from "@/plugins/AuthUtils"; import { showToast } from "@/plugins/ToastManager"; -import ArticleListItem from "@/components/ArticleListItem.vue"; +import ArticlesSearchForm from "@/components/ArticlesSearchForm.vue"; library.add( faChevronRight, @@ -363,7 +319,7 @@ Marker.prototype.options.icon = icon({ }); export default { - components: { ArticleListItem }, + components: { ArticlesSearchForm }, data() { return { articles: [], @@ -423,40 +379,6 @@ export default { } ); - // Second accordion (remove articles) - $("#collapseTwo").on("show.bs.collapse", () => { - idau = 0; - this.articles = []; - $("#selectMittenteDel").empty(); - // Fill the authors select - var array = JSON.parse(JSON.stringify(store.perms)); - var authors = JSON.parse(JSON.stringify(store.authorizedauthors)); - - $("#selectMittenteDel").append(''); - array.forEach((perm) => { - if (perm.grant == "authors") { - $("#selectMittenteDel").append( - '" - ); - idau++; - } - }); - - // Refresh the list of articles of the selected author - $("#selectMittenteDel").change(() => { - this.getArticlesFromAuthor(); - }); - - // Refresh the list of articles based on the changed title - $("#titoloArticoloDel").change(() => { - this.getArticlesFromAuthor(); - }); - }); - // Fetch categories and fill the select axios .get(API_BASE_URL + "/tags") @@ -648,10 +570,6 @@ export default { } }); - // If an article is deleted, remove it from the list - this.emitter.on("article-deleted", (id) => { - this.articles = this.articles.filter((article) => article.id != id); - }); // Initialize extra libraries (leaflet, tempusdominus). // Only needed if the article needs "extra" fields (location and/or date) @@ -698,75 +616,6 @@ export default { }, methods: { - getArticlesFromAuthor(more) { - var id = $("#selectMittenteDel").val(); - var titolo = $("#titoloArticoloDel").val(); - // The empty author is selected - if (id == 0) { - return; - } - if (more) { - this.deletedPageOffset++; - $("#loadMore").html( - "" - ); - } - - $("#loading").removeClass("d-none"); - var path = - "/articles?author_id=" + - id + - "&limit=3&sort=date&platform=3&pageOffset=" + - this.deletedPageOffset; - if (titolo != "") { - this.deletedPageOffset = 0; - path += "&title=" + titolo; - } - axios - .get(API_BASE_URL + path) - .then( - (response) => { - if (more) { - this.articles = this.articles.concat(response.data.articles); - } else { - this.articles = []; - this.articles = response.data.articles; - } - if (response.data.articles.length < 3) { - this.canLoadMore = false; - } else { - this.canLoadMore = true; - } - }, - (error) => { - if (error.response.status == 404) { - if (more) { - this.canLoadMore = false; - return; - } - this.articles = []; - showToast("Nessun articolo trovato", "info"); - return; - } else { - loggers.mainLogger.error( - "articoli", - "Error while fetching articles" - ); - loggers.mainLogger.error("articoli", error); - showToast( - "Errore nel caricamento degli articoli: " + - (error.response.data.error || error.response.data.title), - "error" - ); - } - } - ) - .finally(() => { - $("#loading").addClass("d-none"); - $("#loadMore").html("Carica altri"); - }); - return; - }, saveAndLoadArticleContent(el) { // If the button clicked is the english one, save the italian content and load the english one if (el.id == "btnradioita") { From 36ac5baa48adfe21fefcc4a08cedc67727ce48b7 Mon Sep 17 00:00:00 2001 From: Francesco Lo Faro Date: Mon, 18 Sep 2023 22:27:07 +0200 Subject: [PATCH 07/10] tweaking --- src/components/ArticlesSearchForm.vue | 39 ++++++++++++++------------- src/views/ArticlesView.vue | 1 - 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/components/ArticlesSearchForm.vue b/src/components/ArticlesSearchForm.vue index 7c50ae6..9cc89ea 100644 --- a/src/components/ArticlesSearchForm.vue +++ b/src/components/ArticlesSearchForm.vue @@ -80,33 +80,19 @@ export default { deletedPageOffset: 0, isLoading: false, idau: 0, + store: usePolifemoStore() }; }, mounted() { - const store = usePolifemoStore(); - + this.fillAuthorOptions(); // If an article is deleted, remove it from the list this.emitter.on("article-deleted", (id) => { - this.articles = this.articles.filter((article) => article.id != id); + this.articles = this.articles.filter((article) => article.id != id); }); // Wait for the permissions to load before adding the authors to the select this.emitter.on("permissions-refreshed", () => { - var array = JSON.parse(JSON.stringify(store.perms)); - var authors = JSON.parse(JSON.stringify(store.authorizedauthors)); - $("#selectMittente").append(''); - array.forEach((perm) => { - if (perm.grant == "authors") { - $("#selectMittente").append( - '" - ); - this.idau++; - } - }); + this.fillAuthorOptions(); }); }, methods: { @@ -173,6 +159,23 @@ export default { this.isLoading = false; }); return; + }, + fillAuthorOptions() { + var array = JSON.parse(JSON.stringify(this.store.perms)); + var authors = JSON.parse(JSON.stringify(this.store.authorizedauthors)); + $("#selectMittente").append(''); + array.forEach((perm) => { + if (perm.grant == "authors") { + $("#selectMittente").append( + '" + ); + this.idau++; + } + }); } } }; diff --git a/src/views/ArticlesView.vue b/src/views/ArticlesView.vue index 729a615..af0205c 100644 --- a/src/views/ArticlesView.vue +++ b/src/views/ArticlesView.vue @@ -570,7 +570,6 @@ export default { } }); - // Initialize extra libraries (leaflet, tempusdominus). // Only needed if the article needs "extra" fields (location and/or date) document From da9993e4a35b7e8ed06fd47bbf3d2e0e0e947a5e Mon Sep 17 00:00:00 2001 From: Francesco Lo Faro Date: Tue, 19 Sep 2023 20:26:42 +0200 Subject: [PATCH 08/10] modular forms --- src/components/ArticleListItem.vue | 23 ++++++++++++++++++----- src/components/ArticlesSearchForm.vue | 22 ++++++++++++++++++---- src/views/ArticlesView.vue | 6 +++++- 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/src/components/ArticleListItem.vue b/src/components/ArticleListItem.vue index 648a4df..42f5266 100644 --- a/src/components/ArticleListItem.vue +++ b/src/components/ArticleListItem.vue @@ -28,6 +28,10 @@ defineProps({ buttons: { type: String, required: true + }, + formoccurrence: { + type: Number, + required: true } }); @@ -72,7 +76,7 @@ library.add(faCalendar, faLocationDot, faTrashCan, faEye);
-
+
@@ -87,17 +91,17 @@ export default { }; }, mounted() { - this.previewBox = this.$el.querySelector("#preview-box-" + this.id); + this.previewBox = this.$el.querySelector("#preview-box-" + this.id + "-" + this.formoccurrence); }, methods: { preview() { - if (this.cherryEditor && $(this.previewbox).hasClass("d-none")) { - $(previewbox).removeClass("d-none"); + if (this.cherryEditor && $(this.previewBox).hasClass("d-none")) { + $(this.previewBox).removeClass("d-none"); } else if (this.cherryEditor && !$(this.previewBox).hasClass("d-none")) { $(this.previewBox).addClass("d-none"); } else { this.cherryEditor = new Cherry({ - id: "preview-box-" + this.id, // Need this trick to avoid a bug always creating the editor in the first element of the list + id: "preview-box-" + this.id + "-" + this.formoccurrence, // Need this trick to avoid a bug always creating the editor in the first element of the list value: this.content.it.content || this.content.en.content, locale: "en_US", editor: { @@ -143,7 +147,16 @@ export default { btn.classList.add("pending"); btn.classList.remove("btn-list-item-action"); btn.innerHTML = "Sicuro?"; + setTimeout(() => { + this.stopPendingDeletion(); + }, 5000); } + }, + stopPendingDeletion() { + var btn = this.$el.querySelector("#btn-delete"); + btn.classList.remove("pending"); + btn.classList.add("btn-list-item-action"); + btn.innerHTML = ''; } } }; diff --git a/src/components/ArticlesSearchForm.vue b/src/components/ArticlesSearchForm.vue index 9cc89ea..4109dc8 100644 --- a/src/components/ArticlesSearchForm.vue +++ b/src/components/ArticlesSearchForm.vue @@ -1,8 +1,20 @@ +