Dodano changelog; poprawki reaktywności

This commit is contained in:
2022-08-20 18:07:21 +02:00
parent 6c4c33cb65
commit 9b252cf205
10 changed files with 218 additions and 84 deletions
+7 -4
View File
@@ -77,12 +77,15 @@ button {
transition: background-color 100ms; transition: background-color 100ms;
} }
button:hover { button:focus-visible {
background-color: #505050; border: 1px solid gold;
} }
button:focus-within { // Text
border: 1px solid gold; .text {
&--accent {
color: gold;
}
} }
// Card modal // Card modal
+3 -4
View File
@@ -11,7 +11,7 @@
<li class="route" v-for="(route, i) in computedRouteList" :key="route.routeName + i"> <li class="route" v-for="(route, i) in computedRouteList" :key="route.routeName + i">
<img @click="removeRoute(i)" class="route-delete" src="/icon-trash.svg" alt="icon trash" /> <img @click="removeRoute(i)" class="route-delete" src="/icon-trash.svg" alt="icon trash" />
<form> <form action="javascript:void(0);">
<div>Szlak: <input type="text" v-model="route.routeName" /></div> <div>Szlak: <input type="text" v-model="route.routeName" /></div>
<div> <div>
<input <input
@@ -128,11 +128,11 @@
</div> </div>
</template> </template>
<script lang="ts">import { defineComponent } from 'vue'; <script lang="ts">
import { defineComponent } from 'vue';
import changeMixin from '../mixins/changeMixin'; import changeMixin from '../mixins/changeMixin';
import { useStore } from '../store'; import { useStore } from '../store';
export default defineComponent({ export default defineComponent({
setup() { setup() {
return { return {
@@ -186,7 +186,6 @@ export default defineComponent({
this.routeBackup = this.currentRoutes; this.routeBackup = this.currentRoutes;
} }
// console.log(this.currentRoutes + " git"); // console.log(this.currentRoutes + " git");
}, },
methods: { methods: {
+67 -13
View File
@@ -52,6 +52,18 @@
<button style="margin-left: 0.5em" @click="clearInput">Wyczyść</button> <button style="margin-left: 0.5em" @click="clearInput">Wyczyść</button>
</div> </div>
<div class="pane">
<button @click="changelogVisible = !changelogVisible">
{{ changelogVisible ? 'Ukryj' : 'Pokaż' }} changelog
</button>
</div>
<div class="changelog" v-if="changelogVisible">
<div style="margin-bottom: 0.25em">Changelog:</div>
<div v-html="changelog || 'brak zmian'"></div>
</div>
</div> </div>
</template> </template>
@@ -59,8 +71,10 @@
import axios from 'axios'; import axios from 'axios';
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
import dataMixin from '../mixins/dataMixin'; import dataMixin from '../mixins/dataMixin';
import routesMixin from '../mixins/routesMixin';
import { useStore } from '../store'; import { useStore } from '../store';
import { SceneryRowItem } from '../types/types'; import { Availability, ChangeProp, HeaderTypes, SceneryRowItem } from '../types/types';
import { getAvailabilityValue } from '../types/typeUitls';
export default defineComponent({ export default defineComponent({
setup() { setup() {
@@ -69,7 +83,45 @@ export default defineComponent({
}; };
}, },
mixins: [dataMixin], data() {
return {
changelogVisible: false,
};
},
mixins: [dataMixin, routesMixin],
computed: {
changelog() {
return this.store.changeList
.map((changeItem) => {
let itemChanges = [];
if (changeItem.toRemove) return `<b class='text--accent'>${changeItem.name} -></b> do usunięcia`;
for (let change in changeItem) {
let propChange = change as ChangeProp;
if (/id|name/.test(propChange)) continue;
let value =
typeof changeItem[propChange] === 'boolean'
? changeItem[propChange]
? 'TAK'
: 'NIE'
: changeItem[propChange];
if (propChange == 'availability') value = getAvailabilityValue(changeItem[propChange] as Availability);
if (propChange == 'routes') value = this.getRouteNames(changeItem[propChange] as string);
itemChanges.push(`<i>${(HeaderTypes as any)[propChange]}:</i> ${value || '-'}`);
}
return `<b class='text--accent'>${changeItem.name} -></b> ` + itemChanges.join('; ');
})
.join(' <br /> ');
},
},
methods: { methods: {
confirmLoadData() { confirmLoadData() {
@@ -108,13 +160,12 @@ export default defineComponent({
async updateListToDb() { async updateListToDb() {
try { try {
const mappedChangeList = Object.entries(this.store.changeList).map(([id, v]) => { const mappedChangeList = this.store.changeList.map((v) => {
if (/^#/.test(id)) { if (/^#/.test(v.id)) {
delete v.id; return { ...v, id: undefined };
return { ...v };
} }
return { id: id, ...v }; return { ...v };
}); });
const response = await axios.post( const response = await axios.post(
@@ -133,7 +184,7 @@ export default defineComponent({
); );
this.store.changesResponse = response.data; this.store.changesResponse = response.data;
alert("Pomyślnie wprowadzono zmiany!") alert('Pomyślnie wprowadzono zmiany!');
this.loadData(); this.loadData();
} catch (error) { } catch (error) {
@@ -172,8 +223,8 @@ export default defineComponent({
id: `#${Math.random().toString(32).substring(2)}`, id: `#${Math.random().toString(32).substring(2)}`,
}; };
this.store.changeList[newSt.id] = { ...newSt }; this.store.changeList.push({ ...newSt });
this.store.changeBackupList[newSt.id] = null; // this.store.changeBackupList[newSt.id] = null;
this.store.searchedSceneryName = name; this.store.searchedSceneryName = name;
this.store.unsavedChanges = true; this.store.unsavedChanges = true;
@@ -184,9 +235,8 @@ export default defineComponent({
restoreList() { restoreList() {
if (this.store.backupList.length == 0) return; if (this.store.backupList.length == 0) return;
this.store.stationList = JSON.parse(this.store.backupList); this.store.stationList = JSON.parse(JSON.stringify(this.store.backupList));
this.store.changeList = {}; this.store.changeList = [];
this.store.changeBackupList = {};
this.store.stationsToRemove = []; this.store.stationsToRemove = [];
this.store.unsavedChanges = false; this.store.unsavedChanges = false;
this.store.searchedSceneryName = ''; this.store.searchedSceneryName = '';
@@ -277,6 +327,10 @@ label#notify {
} }
} }
} }
.changelog {
height: 200px;
overflow: auto;
}
@media screen and (max-width: 550px) { @media screen and (max-width: 550px) {
.pane { .pane {
+39 -32
View File
@@ -1,6 +1,6 @@
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
import { useStore } from '../store'; import { useStore } from '../store';
import { SceneryRowItem } from '../types/types'; import { ChangeProp, SceneryRowItem } from '../types/types';
export default defineComponent({ export default defineComponent({
setup() { setup() {
@@ -13,50 +13,57 @@ export default defineComponent({
addChange(sceneryData: SceneryRowItem, propName: string, oldValue: any, newValue: any) { addChange(sceneryData: SceneryRowItem, propName: string, oldValue: any, newValue: any) {
if (oldValue === newValue) return; if (oldValue === newValue) return;
const changePropName = propName as ChangeProp;
const sceneryId = sceneryData.id; const sceneryId = sceneryData.id;
if (this.store.changeList[sceneryId] === null || !(sceneryId in this.store.changeList)) let changeItem = this.store.changeList.find((item) => item.id == sceneryId);
this.store.changeList[sceneryId] = {};
// if (propName === 'name') { if (!changeItem) {
// const rowStationData = this.store.stationList[this.store.stationList.findIndex((v) => v.id == sceneryId)]; changeItem = { id: sceneryId, name: sceneryData.name };
this.store.changeList.push(changeItem);
// this.store.changeList[sceneryId][propName] = newValue;
// this.store.changeBackupList[sceneryId] = { ...rowStationData, name: oldValue };
// } else {
this.store.changeList[sceneryId][propName] = newValue;
if (!this.store.changeBackupList[sceneryId]) this.store.changeBackupList[sceneryId] = {};
if (this.store.changeBackupList[sceneryId][propName] === undefined)
this.store.changeBackupList[sceneryId][propName] = oldValue;
// }
if (this.store.changeList[sceneryId][propName] == this.store.changeBackupList[sceneryId][propName]) {
delete this.store.changeList[sceneryId][propName];
delete this.store.changeBackupList[sceneryId][propName];
if (Object.keys(this.store.changeList[sceneryId]).length == 0) delete this.store.changeList[sceneryId];
if (Object.keys(this.store.changeBackupList[sceneryId]).length == 0)
delete this.store.changeBackupList[sceneryId];
} }
this.store.unsavedChanges = Object.keys(this.store.changeList).length != 0; changeItem[changePropName] = newValue;
const sceneryBackup = this.store.backupList.find((scenery) => scenery.id == sceneryId);
if (!sceneryBackup) return;
if (sceneryBackup && sceneryBackup[changePropName] == changeItem[changePropName])
delete changeItem[changePropName];
if (Object.keys(changeItem).length == 2 && changeItem.id)
this.store.changeList = this.store.changeList.filter((item) => changeItem?.id != item.id);
// if (
// changeItem[changePropName] !== undefined &&
// backupChangeItem[changePropName] !== undefined &&
// changeItem[changePropName] == backupChangeItem[changePropName]
// ) {
// console.log('delete');
// delete changeItem[changePropName];
// delete backupChangeItem[changePropName];
// if (Object.keys(changeItem).length == 1 && changeItem.id)
// this.store.changeList = this.store.changeList.filter((item) => changeItem?.id != item.id);
// if (Object.keys(backupChangeItem).length == 1 && backupChangeItem.id)
// this.store.changeBackupList = this.store.changeList.filter((item) => backupChangeItem?.id != item.id);
// }
this.store.unsavedChanges = this.store.changeList.length != 0;
}, },
addRemovalChange(sceneryData: SceneryRowItem) { addRemovalChange(sceneryData: SceneryRowItem) {
const sceneryId = sceneryData.id; const sceneryId = sceneryData.id;
this.store.changeBackupList[sceneryId] = { ...sceneryData }; let changeItem = this.store.changeList.find((item) => item.id == sceneryId);
this.store.changeList[sceneryId] = { if (!changeItem) this.store.changeList.push({ id: sceneryId, name: sceneryData.name, toRemove: true });
name: sceneryData.name, else changeItem['toRemove'] = true;
toRemove: true,
};
this.store.unsavedChanges = Object.keys(this.store.changeList).length != 0; this.store.unsavedChanges = Object.keys(this.store.changeList).length != 0;
console.log(this.store.changeList); console.log(this.store.changeList);
}, },
}, },
+1 -2
View File
@@ -29,11 +29,10 @@ export default defineComponent({
}) })
).data; ).data;
this.store.backupList = JSON.stringify(data); this.store.backupList = JSON.parse(JSON.stringify(data));
this.store.stationList = data; this.store.stationList = data;
this.store.unsavedChanges = false; this.store.unsavedChanges = false;
this.store.changeList = []; this.store.changeList = [];
this.store.changeBackupList = [];
this.store.dataState = 'LOADED'; this.store.dataState = 'LOADED';
} catch (error) { } catch (error) {
+22
View File
@@ -0,0 +1,22 @@
import { defineComponent } from 'vue';
import { SceneryRowItem } from '../types/types';
export default defineComponent({
methods: {
getRouteNames(routes: SceneryRowItem['routes']) {
return routes
.split(';')
.map((route) => {
// !Oc_2EPB
const props1 = route.split('_')[0];
const props2 = route.split('_')[1];
const isInternal = props1.startsWith('!');
const name = isInternal ? props1.replace('!', '') : props1;
return `${isInternal ? '<u>' + name + '</u>' : name} <span style='color: #aaa'>(${props2[0]}/${props2[1]}/${
props2[2]
}${props2[3] ? '/B' : ''})</span>`;
})
.join(', ');
},
},
});
+5 -5
View File
@@ -1,5 +1,6 @@
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import { IStore } from './types/types'; import { Availability, ChangeProp, HeaderTypes, IStore } from './types/types';
import { getAvailabilityValue } from './types/typeUitls';
export const useStore = defineStore('store', { export const useStore = defineStore('store', {
state: () => state: () =>
@@ -7,11 +8,10 @@ export const useStore = defineStore('store', {
dataState: 'LOADING', dataState: 'LOADING',
unsavedChanges: false, unsavedChanges: false,
stationList: [], stationList: [],
backupList: '', backupList: [],
stationsToRemove: [], stationsToRemove: [],
searchedSceneryName: '', searchedSceneryName: '',
changeList: {}, changeList: [],
changeBackupList: {},
newStationsCount: 0, newStationsCount: 0,
routesModalVisible: true, routesModalVisible: true,
currentStation: null, currentStation: null,
@@ -23,6 +23,6 @@ export const useStore = defineStore('store', {
alertMessage: '', alertMessage: '',
confirmMessage: '', confirmMessage: '',
changesResponse: [] changesResponse: [],
} as IStore), } as IStore),
}); });
+5
View File
@@ -0,0 +1,5 @@
import { Availability, AvailabilityTypes } from './types';
export function getAvailabilityValue(availability: Availability) {
return AvailabilityTypes[availability];
}
+48 -3
View File
@@ -1,4 +1,41 @@
export type Availability = 'default' | 'unavailable' | 'nonPublic' | 'abandoned' | 'nonDefault'; export type Availability = 'default' | 'unavailable' | 'nonPublic' | 'abandoned' | 'nonDefault';
export type ChangeProp =
| 'name'
| 'url'
| 'lines'
| 'project'
| 'reqLevel'
| 'signalType'
| 'controlType'
| 'SUP'
| 'routes'
| 'checkpoints'
| 'authors'
| 'availability';
export enum HeaderTypes {
name = 'Nazwa',
url = 'URL',
lines = 'Linie',
project = 'Projekt',
reqLevel = 'Wym. poziom',
signalType = 'Sygnalizacja',
controlType = 'Sterowanie',
SUP = 'SUP',
authors = 'Autorzy',
routes = 'Szlaki',
checkpoints = 'Posterunki',
availability = 'Dostępność',
toRemove = 'Usuń',
}
export enum AvailabilityTypes {
'default' = 'w paczce',
'nonDefault' = 'poza paczką',
'nonPublic' = 'niepubliczna',
'abandoned' = 'wycofana',
'unavailable' = 'niedostępna',
}
export interface SceneryRowItem { export interface SceneryRowItem {
id: string; id: string;
@@ -16,15 +53,23 @@ export interface SceneryRowItem {
availability: Availability; availability: Availability;
} }
export type ChangeItem = {
[key in ChangeProp]?: string | number | boolean | null;
} & {
id: string;
name: string;
toRemove?: boolean;
};
export interface IStore { export interface IStore {
dataState: string; dataState: string;
unsavedChanges: boolean; unsavedChanges: boolean;
stationList: SceneryRowItem[]; stationList: SceneryRowItem[];
backupList: string; backupList: SceneryRowItem[];
stationsToRemove: string[]; stationsToRemove: string[];
searchedSceneryName: string; searchedSceneryName: string;
changeList: { [key: string]: any }; changeList: ChangeItem[];
changeBackupList: { [key: string]: any };
newStationsCount: number; newStationsCount: number;
routesModalVisible: boolean; routesModalVisible: boolean;
currentStation: SceneryRowItem | null; currentStation: SceneryRowItem | null;
+19 -19
View File
@@ -4,6 +4,7 @@
<hr color="white" /> <hr color="white" />
<TableActions /> <TableActions />
<hr color="white" /> <hr color="white" />
<div class="table_container"> <div class="table_container">
@@ -18,8 +19,13 @@
<tr v-for="(station, row) in sortedStationList" tabindex="0"> <tr v-for="(station, row) in sortedStationList" tabindex="0">
<td v-for="(value, propName) in headerNameList" @click="changeProperty(station, row, propName as string)"> <td v-for="(value, propName) in headerNameList" @click="changeProperty(station, row, propName as string)">
<span v-if="propName === 'url'" :style="station.url ? 'color: gold' : 'color: gray;'">URL</span> <span v-if="propName === 'url'" :style="station.url ? 'color: gold' : 'color: gray;'">URL</span>
<span v-else-if="propName === 'checkpoints'">{{ station[propName] ? 'POKAŻ' : 'DODAJ' }}</span> <span v-else-if="propName === 'checkpoints'">{{ station[propName] ? 'POKAŻ' : 'DODAJ' }}</span>
<span v-else-if="propName === 'routes'" v-html="getRouteNames(station)"></span>
<span v-else-if="propName === 'routes'" v-html="getRouteNames(station.routes)"></span>
<span v-else-if="propName === 'signalType'"> {{ station[propName] }}</span>
<span v-else-if="typeof (station as any)[propName] === 'boolean'"> <span v-else-if="typeof (station as any)[propName] === 'boolean'">
{{ (station as any)[propName] ? '' : '' }} {{ (station as any)[propName] ? '' : '' }}
</span> </span>
@@ -57,10 +63,11 @@ import { useStore } from '../store';
import { SceneryRowItem, Availability } from '../types/types'; import { SceneryRowItem, Availability } from '../types/types';
import RoutesModal from '../components/RoutesModal.vue'; import RoutesModal from '../components/RoutesModal.vue';
import TableActions from '../components/TableActions.vue'; import TableActions from '../components/TableActions.vue';
import routesMixin from '../mixins/routesMixin';
export default defineComponent({ export default defineComponent({
components: { RoutesModal, TableActions }, components: { RoutesModal, TableActions },
mixins: [dataMixin, changeMixin], mixins: [dataMixin, changeMixin, routesMixin],
data: () => ({ data: () => ({
headerNameList: { headerNameList: {
@@ -103,23 +110,6 @@ export default defineComponent({
}, },
methods: { methods: {
getRouteNames(station: SceneryRowItem) {
if (!station.routes) return '';
return station.routes
.split(';')
.map((route) => {
// !Oc_2EPB
const props1 = route.split('_')[0];
const props2 = route.split('_')[1];
const isInternal = props1.startsWith('!');
const name = isInternal ? props1.replace('!', '') : props1;
return `${isInternal ? '<u>' + name + '</u>' : name} <span style='color: #aaa'>(${props2[0]}/${props2[1]}/${
props2[2]
}${props2[3] ? '/B' : ''})</span>`;
})
.join(', ');
},
changeProperty(station: SceneryRowItem, row: number, propertyName: string) { changeProperty(station: SceneryRowItem, row: number, propertyName: string) {
this.store.selectedStationName = station.name; this.store.selectedStationName = station.name;
@@ -174,6 +164,10 @@ export default defineComponent({
}, },
removeStation(scenery: SceneryRowItem) { removeStation(scenery: SceneryRowItem) {
const confirmRemove = confirm('Czy na pewno chcesz zaznaczyć tę scenerię do usunięcia?');
if (!confirmRemove) return;
this.store.stationList = this.store.stationList.filter(({ id }) => id != scenery.id); this.store.stationList = this.store.stationList.filter(({ id }) => id != scenery.id);
this.addRemovalChange(scenery); this.addRemovalChange(scenery);
}, },
@@ -245,4 +239,10 @@ td img {
height: 1.45em; height: 1.45em;
vertical-align: middle; vertical-align: middle;
} }
@media screen and (max-width: 550px) {
table {
font-size: 0.85em;
}
}
</style> </style>