From 1ab3abb53ae8e675c00cd7cb4ccbb6d30713178f Mon Sep 17 00:00:00 2001 From: lishutong Date: Sat, 17 Jul 2021 04:13:39 +0000 Subject: [PATCH] Refactor the OTA configuration page using several components. The original code for OTA configuration in the frontend is tightly coupled and hard to maintain. This CL decoupled the job configuration component (OTAOptions.vue), build library (BuildLibrary.vue) and job submission (JobSubmission.js). The BuildLibrary.vue will present the target build list and take selections. Selections will be sent to OTAOptions.vue, where flags are set. Once the setting is complete, an OTAOption object defined by JobSubmission.js will be sent to the backend. This design can be viewed in go/ota-dashboard-doc : detailed design - TASK CONFIGURATION. This has several benefits: (a) easier for future maintainence. (b) The original code cannot easily be reused for batch OTA package generation. Now, only the OTAOptions.vue has to be modified for this purpose. Test: Mannual tested. Unit tests will be added in following CLs. Change-Id: I846d0c242cd6ed51478dd4d1a3e4c5fb8878aba1 --- tools/otagui/src/components/BuildLibrary.vue | 120 +++++++++ tools/otagui/src/components/OTAOptions.vue | 150 +++++++++++ .../otagui/src/components/PartialCheckbox.vue | 32 ++- tools/otagui/src/router/index.js | 4 +- tools/otagui/src/services/JobSubmission.js | 37 +++ tools/otagui/src/views/JobConfigure.vue | 55 ++++ tools/otagui/src/views/SimpleForm.vue | 242 ------------------ 7 files changed, 387 insertions(+), 253 deletions(-) create mode 100644 tools/otagui/src/components/BuildLibrary.vue create mode 100644 tools/otagui/src/components/OTAOptions.vue create mode 100644 tools/otagui/src/services/JobSubmission.js create mode 100644 tools/otagui/src/views/JobConfigure.vue delete mode 100644 tools/otagui/src/views/SimpleForm.vue diff --git a/tools/otagui/src/components/BuildLibrary.vue b/tools/otagui/src/components/BuildLibrary.vue new file mode 100644 index 000000000..7f27732c9 --- /dev/null +++ b/tools/otagui/src/components/BuildLibrary.vue @@ -0,0 +1,120 @@ + + + + + \ No newline at end of file diff --git a/tools/otagui/src/components/OTAOptions.vue b/tools/otagui/src/components/OTAOptions.vue new file mode 100644 index 000000000..f19db5c50 --- /dev/null +++ b/tools/otagui/src/components/OTAOptions.vue @@ -0,0 +1,150 @@ + + + \ No newline at end of file diff --git a/tools/otagui/src/components/PartialCheckbox.vue b/tools/otagui/src/components/PartialCheckbox.vue index ce4be4dc8..2c369e637 100644 --- a/tools/otagui/src/components/PartialCheckbox.vue +++ b/tools/otagui/src/components/PartialCheckbox.vue @@ -21,7 +21,7 @@ {{ label }} @@ -38,34 +38,48 @@ export default { default: new Array(), }, modelValue: { - type: Map, - default: new Map(), + type: String, + required: true }, }, data() { return { selectAll: 1, selectAllText: ['Select All', 'Unselect All'], + partitionSelected: new Map() + } + }, + watch: { + partitionSelected: { + handler: function() { + let list = '' + for (let [key, value] of this.partitionSelected) { + if (value) { + list += key + ' ' + } + } + this.$emit('update:modelValue', list) + }, + deep: true } }, mounted() { // Set the default value to be true once mounted for (let key of this.labels) { - this.modelValue.set(key, true) + this.partitionSelected.set(key, true) } }, methods: { updateSelected(newSelect) { - this.modelValue.set(newSelect, !this.modelValue.get(newSelect)) - this.$emit('update:modelValue', this.modelValue) + this.partitionSelected.set(newSelect, !this.partitionSelected.get(newSelect)) }, revertAllSelection() { this.selectAll = 1 - this.selectAll - for (let key of this.modelValue.keys()) { - this.modelValue.set(key, Boolean(this.selectAll)) + for (let key of this.partitionSelected.keys()) { + this.partitionSelected.set(key, Boolean(this.selectAll)) } }, - }, + } } diff --git a/tools/otagui/src/router/index.js b/tools/otagui/src/router/index.js index 6f3c3a2fd..a68ac7506 100644 --- a/tools/otagui/src/router/index.js +++ b/tools/otagui/src/router/index.js @@ -2,7 +2,7 @@ import { createRouter, createWebHistory } from 'vue-router' import JobList from '@/views/JobList.vue' import JobDetails from '@/views/JobDetails.vue' import About from '@/views/About.vue' -import SimpleForm from '@/views/SimpleForm.vue' +import JobConfigure from '@/views/JobConfigure.vue' const routes = [ { @@ -24,7 +24,7 @@ const routes = [ { path: '/create', name: 'Create', - component: SimpleForm + component: JobConfigure } ] diff --git a/tools/otagui/src/services/JobSubmission.js b/tools/otagui/src/services/JobSubmission.js new file mode 100644 index 000000000..22f0436ba --- /dev/null +++ b/tools/otagui/src/services/JobSubmission.js @@ -0,0 +1,37 @@ +/** + * @fileoverview Class OTAInput is used to configure and create a process in + * the backend to to start OTA package generation. + * @package vue-uuid + * @package ApiServices + */ +import { uuid } from 'vue-uuid' +import ApiServices from './ApiService.js' + +export class OTAConfiguration { + /** + * Initialize the input for the api /run/ + */ + constructor() { + this.verbose = false, + this.target = '', + this.output = 'output/' + String(this.id) + '.zip', + this.incremental = '', + this.isIncremental = false, + this.partial = '', + this.isPartial = false, + this.extra = '', + this.id = uuid.v1() + } + + /** + * Start the generation process, will throw an error if not succeed + */ + async sendForm() { + try { + let response = await ApiServices.postInput(JSON.stringify(this), this.id) + return response.data + } catch (err) { + throw err + } + } +} \ No newline at end of file diff --git a/tools/otagui/src/views/JobConfigure.vue b/tools/otagui/src/views/JobConfigure.vue new file mode 100644 index 000000000..40e55e056 --- /dev/null +++ b/tools/otagui/src/views/JobConfigure.vue @@ -0,0 +1,55 @@ + + + + +> \ No newline at end of file diff --git a/tools/otagui/src/views/SimpleForm.vue b/tools/otagui/src/views/SimpleForm.vue deleted file mode 100644 index 7f326a170..000000000 --- a/tools/otagui/src/views/SimpleForm.vue +++ /dev/null @@ -1,242 +0,0 @@ - - - - - \ No newline at end of file