Skip to content

Commit

Permalink
Added accessarea migrations upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Starre, Bryan van der committed Jun 24, 2023
1 parent c3ee966 commit 5516874
Show file tree
Hide file tree
Showing 9 changed files with 227 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .env.development
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
VITE_APPLICATION_NAME="FANTools - Development"
VITE_API_URL="https://pocketbase-test.fatools.site"
VITE_API_URL="https://pocketbase.fatools.site"
VITE_LOCALE_DEFAULT="en"
VITE_LOCALE_FALLBACK="en"
VITE_TOKEN_SECRET="#12223Secret123!456"
40 changes: 38 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"bootstrap": "^5.2.3",
"bootstrap-vue": "^2.23.1",
"bootstrap-vue-3": "^0.1.13",
"csv-parser": "^3.0.0",
"electron-is-dev": "^2.0.0",
"electron-updater": "^5.3.0",
"install": "^0.13.0",
Expand Down Expand Up @@ -71,6 +72,7 @@
"@vue/compiler-sfc": "^3.1.0",
"electron": "^22.0.2",
"electron-builder": "^23.6.0",
"papaparse": "^5.4.1",
"sass": "^1.52.3",
"sass-loader": "^13.0.0",
"vite": "^2.9.9",
Expand Down
3 changes: 3 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
<b-nav-item :to="{ name: 'admin-userpanel'}" v-role:any="'super-admin'">
User Panel
</b-nav-item>
<b-nav-item :to="{ name: 'admin-upload-migrations'}" v-role:any="'super-admin'">
Upload Migrations
</b-nav-item>
<b-nav-item @click="this.logout()">
Logout
</b-nav-item>
Expand Down
5 changes: 3 additions & 2 deletions src/router/admin.routes.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Dashboard } from '@/views/admin';
import { Dashboard, UploadMigration } from '@/views/admin';

export default {
path: '/admin',
children: [
{ path: 'dashboard', name: 'admin-userpanel', component: Dashboard }
{ path: 'dashboard', name: 'admin-userpanel', component: Dashboard },
{ path: 'upload-migrations', name: 'admin-upload-migrations', component: UploadMigration }
]
};
24 changes: 23 additions & 1 deletion src/stores/database.store.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,29 @@ export const useDatabaseStore = defineStore({
},

async create (values, collection) {
return await db.collection(collection).create(values)
return await db.collection(collection).create(values, {
"$autoCancel": false,
})
},

async firstItem (collection, filter) {
return await db.collection(collection).getList(1, 1, {
filter: filter
});
},

async fullList (collection) {
return await db.collection(collection).getFullList()
},

async getDuplicatedRows(rows) {

let dslams = rows.data.map(v => v.Dslam)

const filter = dslams.map((id) => `dslam="${id}"`).join("||");

const records = await db.collection("migrations_duplicate").getFullList({ filter });
console.log(records)
}
}
});
143 changes: 143 additions & 0 deletions src/views/admin/UploadMigration.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<template>
<b-card no-body class="border-0 p-2">
<template #header>
<div class="d-flex justify-content-between">
<CardHeader title="Import CSV to Accessarea Migrations"> </CardHeader>
</div>
</template>
<b-card-body>
<div class="mb-3">
<input
class="form-control"
type="file"
accept=".csv"
v-on:change="onFileChange"
/>
</div>
<b-progress :value="loadedState" max="100" variant="success" show-progress striped :animated="animate" v-if="loadedState > 0 && loadedState != 100"></b-progress>

<template v-if="loadedState == 100">
{{ this.file.name }} is uplaoded
</template>

</b-card-body>
<b-card-footer class="p-0 m-0" v-if="parsed || loadedState == 100">
<Form
@submit="onSubmit"
v-slot="{ isSubmitting }"
>
<Button variant="success" :isSubmitting="isSubmitting" text="Submit"></Button>
</Form>
</b-card-footer>
</b-card>
</template>
<script>
import { Form } from 'vee-validate';
import { mapActions, mapWritableState } from 'pinia';
import { useDatabaseStore, useNotificationStore } from '@/stores';
import Papa from 'papaparse';
import CardHeader from '@/components/Card/CardHeader.vue';
import Button from '@/Components/Input/Button.vue';
export default {
data() {
return {
animate: true,
file: '',
content: [],
migrations: [],
parsed: false,
loadedState: 0
}
},
components: {
CardHeader,
Button,
Form
},
computed: {
...mapWritableState(useNotificationStore, {
addNotification: 'notifications'
}),
},
methods: {
...mapActions(useDatabaseStore, {
create: 'create',
fullList: 'fullList',
firstItem: 'firstItem'
}),
async onFileChange(e) {
this.file = e.target.files[0];
const ifAlreadyUploaded = await this.firstItem('migration_files', `file = "${this.file.name}"`);
if(ifAlreadyUploaded.items?.length > 0) {
return this.addNotification.push({ text: 'This file is already been uploaded earlier!', type: 'error'})
}
this.parseFile();
},
parseFile(){
Papa.parse(this.file, {
header: true,
skipEmptyLines: true,
complete: function( results ){
this.content = results;
this.parsed = true;
}.bind(this)
});
},
async onSubmit() {
const response = await this.fullList('migrations');
const exstingDslams = response.map(item => {
return item.dslam
})
let filesProgressed = 0;
for await (let element of this.content.data) {
if(exstingDslams.includes(element.Dslam)) {
return;
}
if(filesProgressed%10 === 0) {
setTimeout(1000)
}
await this.create({
dslam: element.Dslam,
old: element.AA_oud,
new: element.AA_nieuw,
plandate: element.Plandatum,
type: element.Type_Migratie
}, 'migrations');
filesProgressed++;
this.loadedState = filesProgressed / this.content.data.length * 100;
this.parsed = false;
}
await this.create({
file: this.file.name,
finished: true
}, 'migration_files');
return this.addNotification.push({ text: 'Migrations successfully uploaded!', type: 'success'})
}
},
}
</script>
3 changes: 2 additions & 1 deletion src/views/admin/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { default as Dashboard } from './Dashboard.vue';
export { default as Dashboard } from './Dashboard.vue';
export { default as UploadMigration } from './UploadMigration.vue';
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,13 @@ csstype@^3.1.0:
resolved "https://registry.npmjs.org/csstype/-/csstype-3.1.1.tgz"
integrity sha512-DJR/VvkAvSZW9bTouZue2sSxDwdTN92uHjqeKVm+0dAqdfNykRzQ95tay8aXMBAAPpUiq4Qcug2L7neoRh2Egw==

csv-parser@^3.0.0:
version "3.0.0"
resolved "https://registry.npmjs.org/csv-parser/-/csv-parser-3.0.0.tgz"
integrity sha512-s6OYSXAK3IdKqYO33y09jhypG/bSDHPuyCme/IdEHfWpLf/jKcpitVFyOC6UemgGk8v7Q5u2XE0vvwmanxhGlQ==
dependencies:
minimist "^1.2.0"

debug@^2.6.8:
version "2.6.9"
resolved "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz"
Expand Down Expand Up @@ -2025,6 +2032,11 @@ p-cancelable@^2.0.0:
resolved "https://registry.npmjs.org/p-cancelable/-/p-cancelable-2.1.1.tgz"
integrity sha512-BZOr3nRQHOntUjTrH8+Lh54smKHoHyur8We1V8DSMVrl5A2malOOwuJRnKRDjSnkoeBh4at6BwEnb5I7Jl31wg==

papaparse@^5.4.1:
version "5.4.1"
resolved "https://registry.npmjs.org/papaparse/-/papaparse-5.4.1.tgz"
integrity sha512-HipMsgJkZu8br23pW15uvo6sib6wne/4woLZPlFf3rpDyMe9ywEXUsuD7+6K9PRkJlVT51j/sCOYDKGGS3ZJrw==

path-is-absolute@^1.0.0:
version "1.0.1"
resolved "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz"
Expand Down

0 comments on commit 5516874

Please sign in to comment.