Skip to content

Commit

Permalink
refactor: rename nextcloud on nc
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin-Guillemin committed Aug 30, 2024
1 parent 3a96ffc commit da25653
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 25 deletions.
12 changes: 6 additions & 6 deletions src/main/webapp/src/components/FileMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<script setup lang="ts">
import { useAppStore, useConfigurationStore, useFileStore, useHomeStore } from '@/stores';
import { Tabs } from '@/types/enums';
import { downloadFileOrBlob, saveOnNextcloud, toFile } from '@/utils';
import { downloadFileOrBlob, saveOnNc, toFile } from '@/utils';
import { storeToRefs } from 'pinia';
import { ref } from 'vue';
import { useI18n } from 'vue-i18n';
Expand All @@ -28,7 +28,7 @@ const appStore = useAppStore();
const { isApp } = storeToRefs(appStore);

const configurationStore = useConfigurationStore();
const { isNextcloudAvailable, isSettings } = storeToRefs(configurationStore);
const { isNcAvailable, isSettings } = storeToRefs(configurationStore);

const fileStore = useFileStore();
const { loadFile } = fileStore;
Expand Down Expand Up @@ -75,8 +75,8 @@ const onHistories = async (): Promise<void> => {

const onExport = async (): Promise<void> => {
await getFile();
if (!file.value || !isNextcloudAvailable.value) return;
await saveOnNextcloud(toFile(file.value), file.value.associatedApp.extension);
if (!file.value || !isNcAvailable.value) return;
await saveOnNc(toFile(file.value), file.value.associatedApp.extension);
};

const onDownload = async (): Promise<void> => {
Expand Down Expand Up @@ -131,9 +131,9 @@ const onDelete = async (): Promise<void> => {
@click="onHistories"
/>
<v-list-item
v-if="isNextcloudAvailable"
v-if="isNcAvailable"
prepend-icon="fas fa-cloud"
:title="t('menu.item.exportOnNextcloud')"
:title="t('menu.item.exportOnNc')"
rounded="xl"
@click="onExport"
/>
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/src/locales/en/menus.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"information": "Information",
"share": "Share",
"histories": "Historiques",
"exportOnNextcloud": "Export on Nextcloud",
"exportOnNc": "Export on Nextcloud",
"download": "Download",
"delete": "Delete"
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/src/locales/en/toasts.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"toast": {
"loadFiles": "Unable to load file list",
"loadFile": "Unable to load file",
"nextcloud": {
"nc": {
"200": "\"{fileName}\" has been {status}\non Nextcloud",
"201": "created",
"204": "updated",
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/src/locales/fr/menus.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"information": "Informations",
"share": "Partages",
"histories": "Historiques",
"exportOnNextcloud": "Exporter sur Nextcloud",
"exportOnNc": "Exporter sur Nextcloud",
"download": "Télécharger",
"delete": "Supprimer"
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/src/locales/fr/toasts.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"toast": {
"loadFiles": "Impossible de charger la liste des fichiers",
"loadFile": "Impossible de charger le fichier",
"nextcloud": {
"nc": {
"200": "\"{fileName}\" a été {status}\nsur Nextcloud",
"201": "crée",
"204": "mis à jour",
Expand Down
8 changes: 4 additions & 4 deletions src/main/webapp/src/stores/configurationStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
import { getConfiguration } from '@/services/api';
import type { AssociatedApp, Configuration, Soffit } from '@/types';
import { errorHandler, initToken, setNextcloudUri, useEntTheme } from '@/utils';
import { errorHandler, initToken, setNcUri, useEntTheme } from '@/utils';
import { initAppsRoutes } from '@/utils/routerUtils.ts';
import { defineStore } from 'pinia';
import { computed, ref, watch } from 'vue';
Expand All @@ -34,7 +34,7 @@ export const useConfigurationStore = defineStore('configuration', () => {
const response = await getConfiguration();
configuration.value = response.data;
if (!configuration.value) return false;
if (isNextcloudAvailable.value) setNextcloudUri(configuration.value.front.nextcloudUri);
if (isNcAvailable.value) setNcUri(configuration.value.front.nextcloudUri);
await initToken(configuration.value.front.userInfoApiUrl);
await useEntTheme(configuration.value.front.extendedUportalHeader.templateApiPath);
await initAppsRoutes(configuration.value.front.apps);
Expand Down Expand Up @@ -69,7 +69,7 @@ export const useConfigurationStore = defineStore('configuration', () => {

/* -- Nextcloud -- */

const isNextcloudAvailable = computed<boolean>(() => (configuration.value?.front.nextcloudUri ?? '').length > 0);
const isNcAvailable = computed<boolean>(() => (configuration.value?.front.nextcloudUri ?? '').length > 0);

/* -- User -- */

Expand Down Expand Up @@ -100,7 +100,7 @@ export const useConfigurationStore = defineStore('configuration', () => {
isReady,
infoName,
appName,
isNextcloudAvailable,
isNcAvailable,
user,
isSoffitOk,
lastNavigation,
Expand Down
22 changes: 11 additions & 11 deletions src/main/webapp/src/utils/nextcloudUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const { VITE_AXIOS_TIMEOUT } = import.meta.env;

const { t } = i18n.global;

let nextcloudBaseUri: string | undefined;
let ncBaseUri: string | undefined;

const instance = axios.create({
timeout: VITE_AXIOS_TIMEOUT,
Expand All @@ -34,41 +34,41 @@ const instance = axios.create({
},
});

const setNextcloudUri = (uri: string): void => {
const setNcUri = (uri: string): void => {
if (uri.length <= 0) return;
nextcloudBaseUri = interpolate(uri, { domain: window.location.hostname });
instance.defaults.baseURL = `${nextcloudBaseUri}/remote.php/dav/files/`;
ncBaseUri = interpolate(uri, { domain: window.location.hostname });
instance.defaults.baseURL = `${ncBaseUri}/remote.php/dav/files/`;
};

const saveOnNextcloud = async (file: File, type: string): Promise<void> => {
const saveOnNc = async (file: File, type: string): Promise<void> => {
const configurationStore = useConfigurationStore();
const { user } = storeToRefs(configurationStore);

try {
const response = await saveNcFile(user.value.sub, file, type);
if ([201, 204].includes(response.status)) {
toast.success(
t('toast.nextcloud.200', {
t('toast.nc.200', {
fileName: `${file.name}.${type}`,
status: t(`toast.nextcloud.${response.status}`),
status: t(`toast.nc.${response.status}`),
}),
{
onClick: () => {
window.open(`${nextcloudBaseUri}/`, '_blank');
window.open(`${ncBaseUri}/`, '_blank');
},
},
);
}
} catch (error: any) {
if (error.response?.status === 401) {
toast.error(t('toast.nextcloud.401'), {
toast.error(t('toast.nc.401'), {
autoClose: false,
onClick: () => {
window.open(`${nextcloudBaseUri}/apps/user_cas/login`, '_blank');
window.open(`${ncBaseUri}/apps/user_cas/login`, '_blank');
},
});
} else errorHandler(error, true);
}
};

export { instance as ncInstance, setNextcloudUri, saveOnNextcloud };
export { instance as ncInstance, setNcUri, saveOnNc };

0 comments on commit da25653

Please sign in to comment.