This commit is contained in:
2020-08-07 22:24:49 +00:00
parent 3770cc7fda
commit d2bf0c9000
4 changed files with 272 additions and 0 deletions

View File

@@ -373,6 +373,15 @@ export default {
return this.APIUrl(url);
},
/////////////////////////////
// logo download URL
// (size= 'small', 'medium', 'large')
logoUrl(size) {
//http://localhost:7575/api/v8/logo/small
let url = "logo/" + size;
return this.APIUrl(url);
},
/////////////////////////////
// REPLACE END OF URL
// (used to change ID in url)
replaceAfterLastSlash(theUrl, theReplacement) {
@@ -573,6 +582,36 @@ export default {
} catch (error) {
handleError("POSTATTACHMENT", error, route);
}
},
///////////////////////////////////
// POST LOGO
//
//
async uploadLogo(fileData, size) {
let that = this;
try {
var data = new FormData();
data.append(fileData.name, fileData);
//-----------------
let fetchOptions = {
method: "post",
mode: "cors",
headers: {
Authorization: "Bearer " + window.$gz.store.state.apiToken
},
body: data
};
let r = await fetch(that.APIUrl("logo/" + size), fetchOptions);
that.statusEx(r);
r = await that.extractBodyEx(r);
return r;
} catch (error) {
handleError("uploadLogo", error, route);
}
}
//---------------

View File

@@ -326,6 +326,12 @@ export default new Router({
/* webpackChunkName: "adm" */ "./views/adm-global-select-templates.vue"
)
},
{
path: "/adm-global-logo",
name: "adm-global-logo",
component: () =>
import(/* webpackChunkName: "adm" */ "./views/adm-global-logo.vue")
},
{
path: "/adm-license",
name: "adm-license",

View File

@@ -0,0 +1,220 @@
<template>
<v-row v-if="formState.ready">
<v-col>
<v-form ref="form">
<!-- Prevent implicit submission of the form on enter key, this is not necessary on a form with a text area which is why I never noticed it with the other forms -->
<v-row>
<gz-error :errorBoxMessage="formState.errorBoxMessage"></gz-error>
<v-col cols="12">
<v-img :src="imageUrl('small')"></v-img>
<v-file-input
v-model="uploadSmall"
accept="image/*"
show-size
label="Small logo"
></v-file-input>
<v-btn color="primary" text @click="upload('small')">{{
$ay.t("Upload")
}}</v-btn>
</v-col>
<v-col cols="12">
<v-img :src="imageUrl('medium')"></v-img>
<v-file-input
v-model="uploadMedium"
accept="image/*"
show-size
label="Medium logo"
></v-file-input>
<v-btn color="primary" text @click="upload('medium')">{{
$ay.t("Upload")
}}</v-btn>
</v-col>
<v-col cols="12">
<v-img :src="imageUrl('large')"></v-img>
<v-file-input
v-model="uploadLarge"
accept="image/*"
show-size
label="Large logo"
></v-file-input>
<v-btn color="primary" text @click="upload('large')">{{
$ay.t("Upload")
}}</v-btn>
</v-col>
</v-row>
</v-form>
</v-col>
</v-row>
</template>
<script>
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* Xeslint-disable */
////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//NOTE: This is a simple form with no need for business rules or validation so stripped out any extraneous code related to all that
//
const FORM_KEY = "adm-global-logo";
export default {
beforeDestroy() {
window.$gz.eventBus.$off("menu-click", clickHandler);
},
async created() {
let vm = this;
try {
await initForm(vm);
vm.formState.ready = true;
vm.readOnly = !vm.rights.change;
window.$gz.eventBus.$on("menu-click", clickHandler);
//NOTE: this would normally be in getDataFromAPI but this form doesn't really need that function so doing it here
//modify the menu as necessary
generateMenu(vm);
vm.formState.loading = false;
} catch (err) {
vm.formState.ready = true;
window.$gz.errorHandler.handleFormError(err, vm);
}
},
data() {
return {
uploadSmall: null,
uploadMedium: null,
uploadLarge: null,
formState: {
ready: false,
dirty: false,
valid: true,
readOnly: false,
loading: true,
errorBoxMessage: null,
appError: null,
serverError: {}
},
rights: window.$gz.role.getRights(window.$gz.type.Global)
};
},
methods: {
imageUrl(size) {
return window.$gz.api.logoUrl(size);
},
async upload(size) {
//similar code in wiki-control
let vm = this;
let fileData = null;
switch (size) {
case "small":
fileData = vm.uploadSmall;
break;
case "medium":
fileData = vm.uploadMedium;
break;
case "large":
fileData = vm.uploadLarge;
break;
default:
return;
}
// let fileData = [];
// for (let i = 0; i < vm.uploadFiles.length; i++) {
// let f = vm.uploadFiles[i];
// fileData.push({ name: f.name, lastModified: f.lastModified });
// }
// let at = {
// ayaId: vm.ayaId,
// ayaType: vm.ayaType,
// files: vm.uploadFiles,
// fileData: JSON.stringify(fileData), //note this is required for an array or it will come to the server as a string [object,object]
// notes: vm.notes ? vm.notes : ""
// };
try {
let res = await window.$gz.api.uploadLogo(fileData, size);
if (res.error) {
window.$gz.errorHandler.handleFormError(res.error);
} else {
// vm.uploadFiles = [];
// vm.updateDisplayList(res.data);
}
} catch (error) {
window.$gz.errorHandler.handleFormError(error);
}
}
}
};
/////////////////////////////
//
//
function clickHandler(menuItem) {
if (!menuItem) {
return;
}
let m = window.$gz.menu.parseMenuItem(menuItem);
if (m.owner == FORM_KEY && !m.disabled) {
switch (m.key) {
// case "save":
// m.vm.submit();
// break;
// case "delete":
// m.vm.remove();
// break;
default:
window.$gz.eventBus.$emit(
"notify-warning",
FORM_KEY + "::context click: [" + m.key + "]"
);
}
}
}
//////////////////////
//
//
function generateMenu(vm) {
let menuOptions = {
isMain: false,
icon: null,
title: "GlobalLogo",
helpUrl: "form-adm-global-logo",
menuItems: []
};
// if (vm.rights.change) {
// menuOptions.menuItems.push({
// title: "Save",
// icon: "fa-save",
// surface: true,
// key: FORM_KEY + ":save",
// vm: vm
// });
// if (vm.rights.delete) {
// menuOptions.menuItems.push({
// title: "ResetToDefault",
// icon: "fa-undo",
// surface: false,
// key: FORM_KEY + ":delete",
// vm: vm
// });
// }
// }
window.$gz.eventBus.$emit("menu-change", menuOptions);
}
/////////////////////////////////
//
//
async function initForm(vm) {
await fetchTranslatedText(vm);
}
//////////////////////////////////////////////////////////
//
// Ensures UI translated text is available
//
async function fetchTranslatedText(vm) {
await window.$gz.translation.cacheTranslations(["Include", "ResetToDefault"]);
}
</script>

View File

@@ -4,6 +4,13 @@
<v-card class="mx-auto" v-if="formState.ready">
<v-list subheader>
<v-subheader>{{ $ay.t("UserInterfaceSettings") }}</v-subheader>
<v-list-item
link
to="adm-global-logo"
:data-cy="!!$ay.dev ? 'logo' : false"
>
<v-list-item-title>{{ $ay.t("GlobalLogo") }}</v-list-item-title>
</v-list-item>
<v-list-item
link
to="adm-global-select-templates"