This commit is contained in:
2022-02-22 16:13:12 +00:00
parent 2128d3d773
commit da2097448e
3 changed files with 206 additions and 5 deletions

View File

@@ -0,0 +1,175 @@
<template>
<gz-dash
icon="$ayiSplotch"
:add-url="'widgets/0'"
:show-more-button="true"
:update-frequency="60000"
v-bind="$attrs"
@dash-refresh="getDataFromApi()"
@dash-more-click="moreClick()"
v-on="$listeners"
>
<template slot="main">
<div class="ml-4 mt-1">
<template v-for="(item, i) in obj"
><span :key="i"
>{{ localizedCurrency(item[1].v)
}}<span class="ml-2"
><a :href="'/widgets/' + item[0].i"> {{ item[0].v }}</a>
<br /></span></span
></template>
</div>
</template>
</gz-dash>
</template>
<script>
/*
TODO: LINK TO LIST FROM HERE, GRID VIEW PREFILTERED AND SORTED
*/
import GzDash from "../components/dash-base.vue";
export default {
components: {
GzDash
},
props: {
maxListItems: { type: Number, default: 10 }
},
data() {
return {
obj: [],
timeZoneName: window.$gz.locale.getResolvedTimeZoneName(),
languageName: window.$gz.locale.getResolvedLanguage(),
hour12: window.$gz.locale.getHour12(),
formUserOptions: {}
};
},
computed: {},
async created() {
await getFormUserOptions(this);
},
methods: {
moreClick() {
// const LIST_FORM_KEY = "widget-list";
// //get current settings for the form
// const formSettings = window.$gz.form.getFormSettings(LIST_FORM_KEY);
// //switch to an unsaved listview and substitute this dash widgets list view criteria
// formSettings.temp.page = 0;
// formSettings.saved.dataTable.listViewId = -1;
// formSettings.saved.dataTable.unsavedListView = LIST_VIEW.listView;
// //save back again
// window.$gz.form.setFormSettings(LIST_FORM_KEY, formSettings);
// //now navigate to the data table list view
// this.$router.push({
// name: "widget-list"
// });
},
async getDataFromApi() {
//http://localhost:7575/api/v8.0/schedule/personal
//{"view":1,"dark":false,"start":"2022-02-21T08:00:00.000Z","end":"2022-02-22T07:59:59.000Z","wisuColorSource":"2","wisu":true,"reviews":true,"reminders":true}
// const lv = LIST_VIEW;
// lv.limit = this.maxListItems;
// const res = await window.$gz.api.post("data-list", lv);
// if (!res.error) {
// this.obj = res.data;
// } else {
// this.obj = [];
// }
try {
window.$gz.form.deleteAllErrorBoxErrors(this);
const res = await window.$gz.api.post("schedule/personal", {
view: window.$gz.util.calendarViewToAyaNovaEnum(this.viewType),
dark: this.$store.state.darkMode,
start: window.$gz.locale.localTimeDateStringToUTC8601String(
`${start.date}T00:00:00`,
this.timeZoneName
),
end: window.$gz.locale.localTimeDateStringToUTC8601String(
`${end.date}T23:59:59`,
this.timeZoneName
),
wisuColorSource: this.formUserOptions.wisuColorSource,
wisu: this.formUserOptions.wisu, //workorder item scheduled user records
reviews: this.formUserOptions.reviews,
reminders: this.formUserOptions.reminders
});
if (res.error) {
this.formState.serverError = res.error;
window.$gz.form.setErrorBoxErrors(this);
} else {
this.events.splice(0);
const timeZoneName = this.timeZoneName;
let i = res.data.length;
while (i--) {
const x = res.data[i];
this.events.push({
start: new Date(
new Date(x.start)
.toLocaleString("sv-SE", {
timeZone: timeZoneName
})
.replace(" ", "T")
).getTime(),
end: new Date(
new Date(x.end)
.toLocaleString("sv-SE", {
timeZone: timeZoneName
})
.replace(" ", "T")
).getTime(),
timed: true,
name: x.name,
color: x.color,
textColor: x.textColor,
type: x.type,
id: x.id,
editable: x.editable,
userId: x.userId
});
}
}
} catch (error) {
window.$gz.errorHandler.handleFormError(error, this);
}
}
}
};
async function getFormUserOptions(vm) {
const res = await window.$gz.api.get(`form-user-options/home-schedule`);
if (res.error) {
vm.formState.serverError = res.error;
window.$gz.form.setErrorBoxErrors(vm);
} else {
if (res.data == null) {
//make a default
vm.formUserOptions = {
firstTime: "00:00",
excludeDaysOfWeek: 0,
wisuColorSource: "2",
wisu: true,
reviews: true,
reminders: true
};
} else {
vm.formUserOptions = JSON.parse(res.data.options);
}
//takes local time in "HH:MM" format and converts to ISO UTC format for picker consumption
const d = new Date();
const temp = new Date(
d.getFullYear(),
d.getMonth(),
d.getDate(),
vm.formUserOptions.firstTime.split(":")[0],
vm.formUserOptions.firstTime.split(":")[1]
);
vm.tempFirstTime = window.$gz.locale.localTimeDateStringToUTC8601String(
temp.toISOString(),
vm.timeZoneName
);
}
}
</script>