diff --git a/app.js b/app.js index a0a55ff..e2faed7 100644 --- a/app.js +++ b/app.js @@ -64,7 +64,14 @@ var shiftStorage = { var ruleStorage = { fetch: function () { 'use strict'; - var rules = JSON.parse(localStorage.getItem(RULE_STORAGE_KEY)) || Rule.defaults(); + var parsed = JSON.parse(localStorage.getItem(RULE_STORAGE_KEY)) | []; + var rules = parsed.length > 0 + ? parsed.map((e,i) => { + var r = Rule.thaw(e); + r.id = i; + return r; + }) + : Rule.defaults(); ruleStorage.uid = rules.length; return rules; }, @@ -75,6 +82,60 @@ var ruleStorage = { } }; +Vue.component('chip-input', { + template: ` +
+ `, + data() { + return { + instance: null, + chips: [] + } + }, + + computed: { + chipsData() { + return this.instance.chipsData; + } + }, + + watch:{ + initData:{ + deep: true, + handler(n,o) { + if (n !== o) { + this.initialize(); + this.$emit('init'); + } + } + } + }, + props: { + name: String, + initData: Array + }, + + methods: { + initialize() { + this.chips = this.initData.map(e => e); + var el = $('#'+this.name)[0]; + this.instance = M.Chips.init(el, { + data: this.chips, + onChipAdd: () => { + this.$emit("change",this.chipsData); + }, + onChipDelete: () => { + this.$emit("change",this.chipsData); + } + }); + } + }, + + mounted() { + this.initialize(); + } +}); + var app = new Vue({ el: '#app', data: { @@ -85,8 +146,10 @@ var app = new Vue({ dp_sheet: '', deletedShift: '', remaining: shiftStorage.count(), - selectedShift: '', - selectedRule: '', + selectedShift: new Shift({}), + selectedShiftIndex: -1, + selectedRule: new Rule({}), + selectedRuleIndex: -1, saveto: 'dienstplan.ics', uploadFileName: "", config: { @@ -99,7 +162,7 @@ var app = new Vue({ display_language: 'de' }, toast_length: 3000 - } + }, }, watch: { shifts: { @@ -107,7 +170,7 @@ var app = new Vue({ 'use strict'; shiftStorage.save(shifts); this.remaining = shifts.length; - M.toast({html:"Änderungen gespeichert.", displayLength:this.config.toast_length}); + this.makeToast("Änderungen gespeichert."); }, deep: true }, @@ -115,12 +178,19 @@ var app = new Vue({ handler: function (rules) { 'use strict'; ruleStorage.save(rules); - M.toast({html:"Änderungen gespeichert.", displayLength:this.config.toast_length}); + this.makeToast("Änderungen gespeichert."); }, deep: true } }, methods: { + updateArten(value){ + this.selectedRule.Arten = value; + }, + updateTitel(value){ + this.selectedRule.Titel = value; + }, + makeToast(message) { M.toast({ html: message, @@ -134,6 +204,7 @@ var app = new Vue({ this.uploadFileName = files[0].name + " [" + Math.round(files[0].size / 1024) + " kB]"; this.makeToast(this.uploadFileName + " ausgewählt"); }, + handleInputFile: function (file) { var reader = new FileReader(); var vm = this; @@ -154,6 +225,7 @@ var app = new Vue({ }; reader.readAsBinaryString(file); }, + parseForErfurt: function (dp) { var arr = XLSX.utils.sheet_to_row_object_array(dp, { range: 1 @@ -180,6 +252,7 @@ var app = new Vue({ } }); }, + parseForStuttgart: function (dp) { var arr = XLSX.utils.sheet_to_json(dp, { header: "A", @@ -217,17 +290,21 @@ var app = new Vue({ } }); }, + addShift: function (shift) { this.shifts.push(shift); }, + removeShift: function (shift) { this.shifts.splice(this.shifts.indexOf(shift), 1); this.makeToast(shift.VEventTitle + " gelöscht"); }, + cleanStorage: function () { this.shifts = []; this.makeToast("Alle Einträge gelöscht"); }, + createDownloadFile: function () { var vCal = new VCalendar("Dienstplan Kalender"); this.shifts.forEach(function (shift) { @@ -245,58 +322,51 @@ var app = new Vue({ this.icsFile = window.URL.createObjectURL(this.blob); this.makeToast(this.saveto + " erstellt."); }, + downloadFile: function () { if (window.navigator.msSaveOrOpenBlob) { window.navigator.msSaveOrOpenBlob(this.blob, this.saveto); } }, + selectShift: function (shift) { this.selectedShift = Shift.thaw(shift); this.keepShift = shift; M.updateTextFields(); $('#shiftModal').modal('open'); }, + saveChanges: function (changedShift) { this.shifts.splice(this.shifts.indexOf(this.keepShift), 1, changedShift); $('#shiftModal').modal('close'); this.keepShift = ''; this.selectedShift = ''; - }, + discardChanges: function (changedShift) { $('#shiftModal').modal('close'); this.keepShift = ''; this.selectedShift = ''; }, - selectRule: function (rule) { - this.selectedRule = new Rule(rule.duration, rule.art, rule.title); - this.keepRule = rule; - $('#rule_arten').chips({ - data: this.selectedRule.Arten - }); - $('#rule_titel').chips({ - data: this.selectedRule.Titel - }); + editRule: function (rule) { + this.selectedRule = Rule.thaw(rule); + this.selectedRuleIndex = this.rules.indexOf(rule); $('#ruleModal').modal('open'); }, - saveRule: function (changedRule) { - changedRule.Arten = $('#rule_arten').chips('data'); - changedRule.Titel = $('#rule_titel').chips('data'); - this.rules.splice(this.rules.indexOf(this.keepRule), 1, changedRule); + saveRule: function () { + this.rules[this.selectedRuleIndex] = this.selectedRule; $('#ruleModal').modal('close'); - this.keepRule = ''; - this.selectedRule = ''; + this.selectedRule = new Rule(); }, - discardRule: function (changedRule) { - this.rules.splice(this.rules.indexOf(this.keepRule), 1, this.keepRule); + discardRule: function () { $('#ruleModal').modal('close'); - this.keepRule = ''; - this.selectedRule = ''; + + this.selectedRule = new Rule(); } }, diff --git a/index.html b/index.html index ab5ed96..2fa7980 100644 --- a/index.html +++ b/index.html @@ -38,6 +38,7 @@
+

Termine

@@ -140,28 +141,36 @@
-
-
-

Regeln für die Dauer

+
+
+

Regeln für die Dauer

Titel der Veranstaltung Art des Dienstes
- +
+ + {{a.tag}} + + + + {{t.tag}} + + +
+
+
@@ -170,17 +179,21 @@