xref: /aosp_15_r20/development/tools/otagui/src/components/ChainOTAOptions.vue (revision 90c8c64db3049935a07c6143d7fd006e26f8ecca)
1<template>
2  <form @submit.prevent="sendForm">
3    <FileList
4      v-model="targetBuilds"
5      label="Target files"
6      :movable="true"
7    />
8    <v-divider />
9    <OTAOptions
10      :targetDetails="targetDetails"
11      :targetBuilds="targetBuilds"
12    />
13    <v-divider class="my-5" />
14    <v-btn
15      block
16      type="submit"
17    >
18      Submit
19    </v-btn>
20  </form>
21</template>
22
23<script>
24import OTAOptions from '@/components/OTAOptions.vue'
25import FileList from '@/components/FileList.vue'
26
27export default {
28  components: {
29    OTAOptions,
30    FileList,
31  },
32  props: {
33    targetDetails: {
34      type: Array,
35      default: () => [],
36    }
37  },
38  data() {
39    return {
40    }
41  },
42  computed: {
43    checkIncremental() {
44      return this.$store.state.otaConfig.isIncremental
45    },
46    targetBuilds: {
47      get() {
48        return this.$store.state.targetBuilds
49      },
50      set(target) {
51        this.$store.commit('SET_TARGETS', target)
52      }
53    }
54  },
55  watch: {
56    checkIncremental: {
57      handler() {
58        // The isIncremental flag has to be set false all the time
59        this.$store.commit('SET_ISINCREMENTAL', false)
60        this.$store.commit('SET_SOURCES', [])
61      }
62    }
63  },
64  created() {
65    this.$store.commit('SET_ISINCREMENTAL', false)
66    this.$store.commit('SET_SOURCES', [])
67    this.$emit('update:handler', this.addIncrementalSources, this.addTargetBuilds)
68  },
69  methods: {
70    /**
71     * Send the configuration to the backend.
72     */
73    async sendForm() {
74      if (this.targetBuilds.length<2) {
75        alert(
76          'At least two OTA packeges has to be given!'
77        );
78        return
79      }
80      try {
81        let response_data = await this.$store.state.otaConfig
82          .sendChainForms(this.targetBuilds)
83        let response_messages = response_data.map(d => d.msg);
84        alert(response_messages.join('\n'))
85        this.$store.state.otaConfig.reset()
86        this.$store.commit('SET_TARGETS', [])
87      } catch (err) {
88        alert(
89          'Job cannot be started properly for the following reasons: ' + err
90        )
91      }
92    },
93    addIncrementalSources (build) {},
94    addTargetBuilds (build) {
95      if (!this.targetBuilds.includes(build)) {
96        this.targetBuilds.push(build)
97      }
98    }
99  },
100}
101</script>