Browse Source

feat: added a way to see convert schemas and to delete schemas

Kristian Vos 4 years ago
parent
commit
7c2e315b24

+ 12 - 0
backend/logic/accountSchema.js

@@ -70,6 +70,18 @@ module.exports = class extends coreClass {
 		});
 	}
 
+	async removeById(schemaId) {
+		return new Promise(async (resolve, reject) => {
+			try { await this._validateHook(); } catch { return; }
+
+			this.accountSchemaModel.deleteOne({ _id: schemaId }, (err, res) => {
+				if (err) reject(new Error("Something went wrong."));
+				else if (res.deletedCount !== 1) reject(new Error("Nothing was removed."));
+				else resolve();
+			});
+		});
+	}
+
 	async getByVersion(version) {
 		return new Promise(async (resolve, reject) => {
 			try { await this._validateHook(); } catch { return; }

+ 34 - 0
backend/logic/convertSchema.js

@@ -38,6 +38,40 @@ module.exports = class extends coreClass {
 		});
 	}
 
+	async getById(schemaId) {
+		return new Promise(async (resolve, reject) => {
+			try { await this._validateHook(); } catch { return; }
+
+			this.convertSchemaModel.findById(schemaId, (err, schema) => {
+				if (err || !schema) reject(new Error("Something went wrong."))
+				else resolve(schema)
+			});
+		});
+	}
+
+	async removeById(schemaId) {
+		return new Promise(async (resolve, reject) => {
+			try { await this._validateHook(); } catch { return; }
+
+			this.convertSchemaModel.deleteOne({ _id: schemaId }, (err, res) => {
+				if (err) reject(new Error("Something went wrong."));
+				else if (res.deletedCount !== 1) reject(new Error("Nothing was removed."));
+				else resolve();
+			});
+		});
+	}
+
+	async getAll() {
+		return new Promise(async (resolve, reject) => {
+			try { await this._validateHook(); } catch { return; }
+
+			this.convertSchemaModel.find({ }, (err, schemas) => {
+				if (err) reject(new Error(err.message));
+				else resolve(schemas)
+			});
+		});
+	}
+
 	async import(name) {
 		return new Promise(async (resolve, reject) => {
 			try { await this._validateHook(); } catch { return; }

+ 12 - 0
backend/logic/io/namespaces/accountSchema.js

@@ -69,6 +69,18 @@ module.exports = {
 		});
 	},
 
+	"removeById": (cb, schemaId) => {
+		accountSchemaModule.removeById(schemaId).then(() => {
+			cb({
+				status: "success"
+			});
+		}).catch(err => {
+			cb({
+				status: "failure"
+			});
+		});
+	},
+
 	"import": (cb, name) => {
 		accountSchemaModule.import(name).then(() => {
 			cb({

+ 38 - 0
backend/logic/io/namespaces/convertSchema.js

@@ -17,6 +17,44 @@ module.exports = {
 		});
 	},
 
+	"getById": (cb, schemaId) => {
+		convertSchemaModule.getById(schemaId).then(schema => {
+			cb({
+				status: "success",
+				schema
+			});
+		}).catch(err => {
+			cb({
+				status: "failure"
+			});
+		});
+	},
+
+	"removeById": (cb, schemaId) => {
+		convertSchemaModule.removeById(schemaId).then(() => {
+			cb({
+				status: "success"
+			});
+		}).catch(err => {
+			cb({
+				status: "failure"
+			});
+		});
+	},
+
+	"getAll": (cb) => {
+		convertSchemaModule.getAll().then(schemas => {
+			cb({
+				status: "success",
+				schemas
+			});
+		}).catch(err => {
+			cb({
+				status: "failure"
+			});
+		});
+	},
+
 	"import": (cb, name) => {
 		convertSchemaModule.import(name).then(() => {
 			cb({

+ 5 - 1
frontend/main.js

@@ -35,13 +35,17 @@ const router = new VueRouter({
 			path: "/convert/:accountId",
 			component: () => import("./vue/pages/ConvertAccount.vue")
 		},
+		{
+			path: "/convert/view/:schemaId",
+			component: () => import("./vue/pages/ViewConvertSchema.vue")
+		},
 		{
 			path: "/options",
 			component: () => import("./vue/pages/Options.vue")
 		},
 		{
 			path: "/schemas/:schemaId",
-			component: () => import("./vue/pages/ViewSchema.vue")
+			component: () => import("./vue/pages/ViewAccountSchema.vue")
 		},
 		{
 			path: "/accounts/add",

+ 69 - 13
frontend/vue/pages/ConvertAccounts.vue

@@ -1,20 +1,16 @@
 <template>
 	<main>
-		<h1>Accounts</h1>
+		<h1>Convert accounts</h1>
 		<hr/>
 		<br/>
-		<input v-model="importConvertSchemaName"/>
-		<button @click="importConvertSchema()" class="button">Import convert schema</button>
-		<br/>
-		<br/>
 		<p>Select/deselect all:</p>
 		<button class="button" v-for="version in versions" @click="toggleVersion(version)">{{version}}</button>
 		<br/>
 		<br/>
-		<data-table ref="datatable"
-			:fields="fields"
-			:sort-order="sortOrder"
-			:data="localData"
+		<data-table ref="accounts-datatable"
+			:fields="accountsFields"
+			:sort-order="accountsSortOrder"
+			:data="accountsLocalData"
 		>
 			<div slot="select-slot" slot-scope="props">
 				<div tabindex="0" name="name" class="checkbox" @click="toggleCheckbox(props.data.accountId)" v-on:keyup.enter="toggleCheckbox(props.data.accountId)" v-on:keyup.space="toggleCheckbox(props.data.accountId)" :class="{ checked: selectedAccounts.indexOf(props.data.accountId) !== -1 }"></div>
@@ -29,8 +25,30 @@
 			</div>
 		</data-table>
 		<br/>
-		<br/>
 		<button @click="convertAccounts()" v-if="!convertingAccounts" class="button">Migrate accounts</button>
+		<br/>
+		<br/>
+		<h1>Convert schemas</h1>
+		<hr/>
+		<br/>
+		<input v-model="importConvertSchemaName"/>
+		<button @click="importConvertSchema()" class="button">Import convert schema</button>
+		<br/>
+		<br/>
+		<data-table ref="convert-schema-datatable"
+			:fields="convertSchemasFields"
+			:sort-order="convertSchemasSortOrder"
+			:data="convertSchemasLocalData"
+		>
+			<div slot="actions-slot" slot-scope="props">
+				<router-link
+					:to="`/convert/view/${props.data.schemaId}`"
+					class="button"
+				>
+					View convert schema
+				</router-link>
+			</div>
+		</data-table>
 	</main>
 </template>
 
@@ -44,10 +62,11 @@ export default {
 	data: () => {
 		return {
 			accounts: [],
+			convertSchemas: [],
 			versions: [],
 			selectedAccounts: [],
 			convertingAccounts: false,
-			fields: [
+			accountsFields: [
 				{
 					name: "select-slot",
 					displayName: ""
@@ -65,7 +84,7 @@ export default {
 					displayName: "Actions"
 				}
 			],
-			sortOrder: [
+			accountsSortOrder: [
 				{
 					field: "name",
 					order: "desc"
@@ -75,11 +94,35 @@ export default {
 					order: "asc"
 				}
 			],
+			convertSchemasFields: [
+				{
+					name: "versionFrom",
+					displayName: "Version from"
+				},
+				{
+					name: "versionTo",
+					displayName: "Version to"
+				},
+				{
+					name: "actions-slot",
+					displayName: "Actions"
+				}
+			],
+			convertSchemasSortOrder: [
+				{
+					field: "versionFrom",
+					order: "asc"
+				},
+				{
+					field: "versionTo",
+					order: "asc"
+				}
+			],
 			importConvertSchemaName: ""
 		}
 	},
 	computed: {
-		localData: function() {
+		accountsLocalData: function() {
 			return this.accounts.map(account => {
 				return {
 					name: account.fields.name[0].name,
@@ -87,6 +130,15 @@ export default {
 					accountId: account._id
 				};
 			});
+		},
+		convertSchemasLocalData: function() {
+			return this.convertSchemas.map(schema => {
+				return {
+					versionFrom: schema.versionFrom,
+					versionTo: schema.versionTo,
+					schemaId: schema._id
+				};
+			});
 		}
 	},
 	methods: {
@@ -141,6 +193,10 @@ export default {
 			socket.emit("accountSchema.getAllVersions", res => {
 				this.versions = res.versions;
 			});
+
+			socket.emit("convertSchema.getAll", res => {
+				this.convertSchemas = res.schemas;
+			});
 		});
 	}
 };

+ 9 - 1
frontend/vue/pages/ViewSchema.vue → frontend/vue/pages/ViewAccountSchema.vue

@@ -31,6 +31,9 @@
 				
 			</div>
 		</div>
+		<br/>
+		<br/>
+		<button class="button" @click="removeSchema()">Remove schema</button>
 	</main>
 </template>
 
@@ -47,7 +50,12 @@ export default {
 	props: {
 	},
 	methods: {
-		
+		removeSchema() {
+			this.socket.emit("accountSchema.removeById", this.schemaId, (res) => {
+				alert(res.status);
+				this.$router.push("/schemas");
+			});
+		}
 	},
 	mounted() {
 		this.schemaId = this.$route.params.schemaId;

+ 65 - 0
frontend/vue/pages/ViewConvertSchema.vue

@@ -0,0 +1,65 @@
+<template>
+	<main v-if="schema">
+		<h1>View schema</h1>
+		<hr/>
+		<br/>
+		<p><b>Version from</b>: {{ schema.versionFrom }}</p>
+		<p><b>Version to</b>: {{ schema.versionTo }}</p>
+		<p><b>Changes</b>: </p>
+		<div class="changes-container">
+			<div v-for="(key, value) in schema.changes" class="change-item">
+				<p><b>{{ key }}</b>: {{ value }}</p>
+			</div>
+		</div>
+		<br/>
+		<br/>
+		<button class="button" @click="removeSchema()">Remove schema</button>
+	</main>
+</template>
+
+<script>
+import io from "../../io.js";
+
+export default {
+	components: {},
+	data: () => {
+		return {
+			schema: null
+		}
+	},
+	props: {
+	},
+	methods: {
+		removeSchema() {
+			this.socket.emit("convertSchema.removeById", this.schemaId, (res) => {
+				alert(res.status);
+				this.$router.push("/convert");
+			});
+		}
+	},
+	mounted() {
+		this.schemaId = this.$route.params.schemaId;
+		io.getSocket(socket => {
+			this.socket = socket;
+
+			this.socket.emit("convertSchema.getById", this.schemaId, res => {
+				if (res.status === "success") {
+					this.schema = res.schema;
+					this.schema.changes = {
+						Test123: "test1232321"
+					}
+				}
+			});
+		});
+	}
+};
+</script>
+
+<style lang="scss" scoped>
+.change-item {
+	padding-left: 25px;
+	border: 1px solid black;
+	margin-right: -1px;
+	margin-bottom: -1px;
+}
+</style>