97 lines
3.1 KiB
TypeScript
97 lines
3.1 KiB
TypeScript
import Vue from "vue";
|
|
|
|
|
|
import { Factory, messageService,awaiter } from '../_base';
|
|
import { MaintenanceService } from "../services/maintenanceService";
|
|
import moment from "moment";
|
|
import Component from "vue-class-component";
|
|
import DatePicker from "vue2-datepicker";
|
|
import { ModalHelper, Modal } from "@/components/modals";
|
|
|
|
@Component({
|
|
components: { modal: Modal, datePicker: DatePicker },
|
|
})
|
|
export default class createMaintenance extends Vue {
|
|
|
|
newMaintenance: any = { type: "EXP_DATE", unitOfMeasure:"H" }
|
|
async beforeCreate() {
|
|
await new MaintenanceService().GetMaintenances();
|
|
}
|
|
|
|
beforeMount() {
|
|
if(!this.isNewMaintenance()){
|
|
this.newMaintenance = ModalHelper.maintenanceModal.currentMaintenance;
|
|
this.newMaintenance.title = this.getTitleMaintenance(this.newMaintenance.createdByCms,this.newMaintenance.id,this.newMaintenance.title);
|
|
|
|
if(this.newMaintenance.type == "EXP_DATE" && this.newMaintenance.deadline){
|
|
this.newMaintenance.date = this.newMaintenance.deadline;
|
|
this.newMaintenance.time = this.newMaintenance.deadline;
|
|
}
|
|
}
|
|
messageService.subscribeToChannel("esc_pressed", args => {
|
|
this.close();
|
|
});
|
|
}
|
|
|
|
beforeDestroy() {
|
|
messageService.deleteChannel("esc_pressed");
|
|
}
|
|
close() {
|
|
messageService.deleteChannel("esc_pressed");
|
|
ModalHelper.HideModal();
|
|
}
|
|
dataformat() {
|
|
return (moment() as any)._locale._longDateFormat.L;
|
|
}
|
|
timeformat() {
|
|
return (moment() as any)._locale._longDateFormat.LT;
|
|
}
|
|
updatePicker(){
|
|
//Fatta per sopperire ad un errore di DatePicker
|
|
this.$forceUpdate();
|
|
}
|
|
getNameFromLanguage() {
|
|
let langName = (this.$store.state).localization.currentLanguage;
|
|
if (langName == "en" || langName == "zh" || langName == "es" || langName == "pt-br" || langName == "fr" || langName == "ru" || langName == "de" || langName == "it" || langName == "cs")
|
|
return langName
|
|
else
|
|
return "en";
|
|
}
|
|
async save(maintenance) {
|
|
if(maintenance.type == "EXP_DATE"){
|
|
let dateTime = new Date(maintenance.date);
|
|
let Time = new Date(maintenance.time);
|
|
dateTime.setHours(Time.getHours());
|
|
dateTime.setMinutes(Time.getMinutes());
|
|
maintenance.deadline = dateTime.toLocaleString("en-US");
|
|
}
|
|
await awaiter(new MaintenanceService().SetMaintenance(maintenance));
|
|
this.close();
|
|
}
|
|
getTitleMaintenance(createdByCms, id, title) {
|
|
if (createdByCms) {
|
|
return this.$options.filters.localize("maint_" + id);
|
|
}
|
|
else {
|
|
return title;
|
|
}
|
|
}
|
|
isNewMaintenance() {
|
|
if (ModalHelper.maintenanceModal.currentMaintenance != null)
|
|
return false;
|
|
return true;
|
|
}
|
|
async modify(maintenance) {
|
|
if(maintenance.type == "EXP_DATE"){
|
|
let dateTime = new Date(maintenance.date);
|
|
let Time = new Date(maintenance.time);
|
|
dateTime.setHours(Time.getHours());
|
|
dateTime.setMinutes(Time.getMinutes());
|
|
maintenance.deadline = dateTime.toLocaleString("en-US");
|
|
}
|
|
await awaiter(new MaintenanceService().ModifyMaintenance(maintenance));
|
|
this.close();
|
|
}
|
|
}
|
|
|