Dodano aktualizowanie zapisanych rozkazów

This commit is contained in:
2022-07-22 15:00:02 +02:00
parent e7b5817f9c
commit 9a97ef61ed
6 changed files with 77 additions and 23 deletions
+3 -2
View File
@@ -9,7 +9,8 @@
{{ order.orderBody['header']['trainNo'] }} {{ order.orderBody['header']['trainNo'] }}
</b> </b>
<br /> <br />
Dodano: {{ new Date(order.createdAt).toLocaleString('pl-PL') }} {{ order.createdAt ? 'Dodano: ' : 'Zaktualizowano: ' }}
{{ new Date(order.createdAt || order.updatedAt || 0).toLocaleString('pl-PL') }}
<br /> <br />
<button class="g-button action" @click="selectLocalOrder(order)">Wybierz</button> <button class="g-button action" @click="selectLocalOrder(order)">Wybierz</button>
<button class="g-button action" @click="removeOrder(order)">Usuń</button> <button class="g-button action" @click="removeOrder(order)">Usuń</button>
@@ -58,7 +59,7 @@ export default defineComponent({
computed: { computed: {
sortedOrderList() { sortedOrderList() {
return this.localOrderList.sort((a, b) => b.createdAt - a.createdAt); return this.localOrderList.sort((a, b) => (b.createdAt || b.updatedAt!) - (a.createdAt || a.updatedAt!));
}, },
}, },
+29 -3
View File
@@ -5,8 +5,11 @@
<div class="message_body" v-html="fullOrderMessage"></div> <div class="message_body" v-html="fullOrderMessage"></div>
<div class="message_actions"> <div class="message_actions">
<button class="g-button action" @click="saveOrder"><img :src="saveIcon" alt="save icon" />Zapisz ten rozkaz</button> <button class="g-button action" @click="saveOrder">Zapisz nowy rozkaz</button>
<button class="g-button action" @click="copyMessage">Kopiuj wiadomość rozkazu</button> <button class="g-button action" @click="copyMessage">Kopiuj treść rozkazu</button>
<button class="g-button action" :data-disabled="!store.chosenLocalOrderId" @click="updateOrder">
Zaktualizuj ten rozkaz
</button>
</div> </div>
<transition name="monit-anim"> <transition name="monit-anim">
@@ -85,7 +88,7 @@ export default defineComponent({
}, },
saveOrder() { saveOrder() {
const savedOrderStatus = this.saveOrderToStorage(); const savedOrderStatus = this.saveLocalOrder();
switch (savedOrderStatus) { switch (savedOrderStatus) {
case -1: case -1:
@@ -104,6 +107,24 @@ export default defineComponent({
break; break;
} }
}, },
updateOrder() {
const updatedOrderStatus = this.updateLocalOrder();
switch (updatedOrderStatus) {
case -1:
this.showActionMonit('<span class="text--warn">Wystąpił błąd podczas aktualizowania tego rozkazu! :/</span>');
break;
case 0:
this.showActionMonit('<span class="text--warn">Nie wybrałeś żadnego zapisanego rozkazu!</span>');
break;
case 1:
this.showActionMonit('Zaktualizowano treść <b class="text--accent">rozkazu</b>!');
break;
}
},
}, },
}); });
</script> </script>
@@ -148,6 +169,11 @@ export default defineComponent({
vertical-align: text-bottom; vertical-align: text-bottom;
margin-right: 0.5em; margin-right: 0.5em;
} }
button[data-disabled='true'] {
user-select: none;
color: #aaa;
}
} }
.action_monit { .action_monit {
+2
View File
@@ -50,6 +50,8 @@ export default defineComponent({
methods: { methods: {
selectOrderType(type: any) { selectOrderType(type: any) {
if (type != this.store.chosenOrderType) this.store.chosenLocalOrderId = '';
this.store.chosenOrderType = type; this.store.chosenOrderType = type;
}, },
}, },
+39 -17
View File
@@ -10,29 +10,29 @@ export default defineComponent({
}, },
methods: { methods: {
saveOrderToStorage() { saveLocalOrder() {
let orderObj: LocalStorageOrder = { let orderObj: LocalStorageOrder = {
id: '', id: '',
orderType: this.store.chosenOrderType, orderType: this.store.chosenOrderType,
orderBody: {}, orderBody: this.store[this.store.chosenOrderType],
orderFooter: this.store.orderFooter, orderFooter: this.store.orderFooter,
createdAt: Date.now(), createdAt: Date.now(),
}; };
switch (this.store.chosenOrderType) { // switch (this.store.chosenOrderType) {
case 'orderN': // case 'orderN':
orderObj['orderBody'] = this.store.orderN; // orderObj['orderBody'] = this.store.orderN;
break; // break;
case 'orderS': // case 'orderS':
orderObj['orderBody'] = this.store.orderS; // orderObj['orderBody'] = this.store.orderS;
break; // break;
case 'orderO': // case 'orderO':
orderObj['orderBody'] = this.store.orderO; // orderObj['orderBody'] = this.store.orderO;
break; // break;
default: // default:
break; // break;
} // }
const headerInfo = orderObj['orderBody']['header']; const headerInfo = orderObj['orderBody']['header'];
@@ -51,10 +51,31 @@ export default defineComponent({
} }
const nextOrderCount = Number(localOrderCount) + 1; const nextOrderCount = Number(localOrderCount) + 1;
orderObj['id'] = `order-${nextOrderCount}`; const orderId = `order-${nextOrderCount}`;
orderObj['id'] = orderId;
localStorage.setItem('orderCount', `${nextOrderCount}`); localStorage.setItem('orderCount', `${nextOrderCount}`);
localStorage.setItem(`order-${nextOrderCount}`, JSON.stringify(orderObj)); localStorage.setItem(orderId, JSON.stringify(orderObj));
this.store.chosenLocalOrderId = orderId;
return 1;
},
updateLocalOrder() {
if (!this.store.chosenLocalOrderId) return 0;
const localOrder = window.localStorage.getItem(this.store.chosenLocalOrderId);
if (!localOrder) return -1;
let orderObj: LocalStorageOrder = {
id: this.store.chosenLocalOrderId,
orderType: this.store.chosenOrderType,
orderBody: this.store[this.store.chosenOrderType],
orderFooter: this.store.orderFooter,
updatedAt: Date.now(),
};
window.localStorage.setItem(this.store.chosenLocalOrderId, JSON.stringify(orderObj));
return 1; return 1;
}, },
@@ -66,6 +87,7 @@ export default defineComponent({
selectLocalOrder(order: LocalStorageOrder) { selectLocalOrder(order: LocalStorageOrder) {
this.store.chosenOrderType = order.orderType; this.store.chosenOrderType = order.orderType;
this.store.chosenLocalOrderId = order.id;
const localOrder = JSON.parse(JSON.stringify(order)); const localOrder = JSON.parse(JSON.stringify(order));
const localOrderBody = localOrder['orderBody']; const localOrderBody = localOrder['orderBody'];
+2
View File
@@ -4,6 +4,8 @@ export const useStore = defineStore('store', {
state: () => { state: () => {
return { return {
chosenOrderType: 'orderN' as 'orderO' | 'orderS' | 'orderN', chosenOrderType: 'orderN' as 'orderO' | 'orderS' | 'orderN',
chosenLocalOrderId: '',
orderMode: 'OrderMessage', orderMode: 'OrderMessage',
orderFooter: { orderFooter: {
+2 -1
View File
@@ -3,5 +3,6 @@ export interface LocalStorageOrder {
orderType: 'orderO' | 'orderS' | 'orderN'; orderType: 'orderO' | 'orderS' | 'orderN';
orderBody: any; orderBody: any;
orderFooter: any; orderFooter: any;
createdAt: number; createdAt?: number;
updatedAt?: number;
} }