diff --git a/package.json b/package.json index 0d06a08..1ad7b08 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,8 @@ "import-categories": "node ./scripts/import_categories.js", "import-stock": "node ./scripts/import_stock.js", "import-history": "node ./scripts/import_history.js", - "import-history-files": "node ./scripts/import_history_files.js" + "import-history-files": "node ./scripts/import_history_files.js", + "renumerate-stock": "node ./scripts/renumerate.js" }, "dependencies": { "@quasar/extras": "^1.16.4", diff --git a/scripts/renumerate.js b/scripts/renumerate.js new file mode 100644 index 0000000..a19fd80 --- /dev/null +++ b/scripts/renumerate.js @@ -0,0 +1,31 @@ +const PocketBase = require('pocketbase').default + +// Initialize the PocketBase client +// const pb = new PocketBase('https://stock.hfsplay.fr') +const pb = new PocketBase('http://127.0.0.1:8090') + +async function main () { + try { + // Authenticate as an admin + // await pb.admins.authWithPassword('gyoza@hfsplay.fr', 'gyozagyoza') // Replace with your admin credentials + await pb.collection('_superusers').authWithPassword('karkinge@gmail.com', 'k4rk1ng3*') // Replace with your admin credentials + console.log('connected !') + let stock = await pb.collection('stock').getFullList({ + sort: 'created' + }) + console.log('Stock items count:', stock.length) + for (let i = 0; i < stock.length; i++) { + const item = stock[i] + if (!item) continue + // Update the item with a new ID + const updatedItem = await pb.collection('stock').update(item.id, { + short_id: i + 1 // Adjust the ID as needed + }) + console.log(`Updated item ${item.id} to new ID ${updatedItem.id}`) + } + } catch (error) { + console.error('Error:', error) + } +} + +main() diff --git a/src/layouts/DefaultLayout.vue b/src/layouts/DefaultLayout.vue index 056f1f7..5c72451 100644 --- a/src/layouts/DefaultLayout.vue +++ b/src/layouts/DefaultLayout.vue @@ -188,6 +188,8 @@ export default { }, async addItem (category) { this.$q.loading.show() + // Get next short id + let shortId = await this.$store.dispatch('core/getNextShortId') let newItem = { available: true, comment: '', @@ -196,7 +198,8 @@ export default { ref: null, state: null, type: category.name, - system: null + system: null, + short_id: shortId } newItem.ref = `${category.code}-${String(this.counters[category.name] + 1).padStart(4, '0')}` await this.$store.dispatch('core/addToCollection', { diff --git a/src/pages/StockItem.vue b/src/pages/StockItem.vue index 0f2aeca..0a3d4b6 100644 --- a/src/pages/StockItem.vue +++ b/src/pages/StockItem.vue @@ -4,6 +4,7 @@
{{ item.name || '---- -- ----' }} {{item.ref}} + {{item.short_id}} Supprimé
{{item.type}}
@@ -151,7 +152,17 @@ - {{ event.user }} + + + {{ event.user }} + + {{ getDate(event.created) }} @@ -178,6 +189,11 @@ color="secondary" />
+ + + + +
{{ getDate(selectedHistory.created) }} + + + + Supprimer Fermer @@ -231,11 +251,12 @@ import QRCode from 'qrcode' export default { name: 'StockItem', - props: ['itemRef'], + props: ['itemRef', 'shortId'], data () { return { showHistoryForm: false, pendingHistory: null, + pendingHistoryType: 'comment', changed: false, hasFile: false, username: null, @@ -272,7 +293,20 @@ export default { } }, created: function () { + if (this.shortId) { + let itemRef = this.stock.find(item => { + return item.short_id === parseInt(this.shortId) + })?.ref + console.log('Redirecting to item with ref:', itemRef) + if (itemRef) this.$router.push(`/item/${itemRef}`) + } this.loadItem() + this.$watch( + () => this.itemRef, + (newId, oldId) => { + this.loadItem() + } + ) }, mounted () { this.username = this.$q.localStorage.getItem('username') @@ -296,6 +330,7 @@ export default { data: { ref: this.itemRef, text: this.pendingHistory, + type: this.pendingHistoryType, user: this.$store.state.core.username, image_file: file, date: date.toISOString() @@ -351,6 +386,17 @@ export default { }) }) }, + setTaskDone (history) { + this.$store.dispatch('core/updateItem', { + collection: 'history', + itemId: history.id, + data: { + ...history, + solved_at: new Date().toISOString(), + solved_by: this.username + } + }) + }, async uploadFile (file) { // Resize and compress the image before uploading const options = { diff --git a/src/router/routes.js b/src/router/routes.js index 601ae4c..beb323e 100644 --- a/src/router/routes.js +++ b/src/router/routes.js @@ -13,7 +13,8 @@ const routes = [ { path: 'dashboard', component: () => import('pages/Dashboard.vue') }, { path: 'category/:categoryCode', props: true, component: () => import('pages/StockItems.vue') }, { path: 'item/:itemRef', props: true, component: () => import('pages/StockItem.vue') }, - { path: 'print-settings', props: true, component: () => import('pages/PrintSettings.vue') } + { path: 'print-settings', props: true, component: () => import('pages/PrintSettings.vue') }, + { path: ':shortId', props: true, component: () => import('pages/StockItem.vue') } ] } ] diff --git a/src/store/core/actions.js b/src/store/core/actions.js index b7297dd..d1cb586 100644 --- a/src/store/core/actions.js +++ b/src/store/core/actions.js @@ -30,6 +30,14 @@ export function deleteItem (store, data) { return pb.collection(data.collection).delete(data.data.id) } +export function getNextShortId (store) { + return pb.collection('stock').getFirstListItem('short_id>0', { + sort: '-short_id' + }).then(item => { + return item.short_id + 1 + }) +} + // export function uploadFile (store, file) { // return Firebase.storage().ref().child(Date.now() + file.name).put(file) // }