|
9 | 9 | />
|
10 | 10 | </el-select>
|
11 | 11 | <el-row :gutter="15">
|
12 |
| - <el-col :span="12" v-if="revisionLeft !== undefined"> |
| 12 | + <el-col :span="12" v-if="revisionLeftIndex !== undefined"> |
13 | 13 | <div class="revision-select mb-3">
|
14 |
| - <el-select v-model="revisionLeft"> |
| 14 | + <el-select v-model="revisionLeftIndex" @change="addQuery"> |
15 | 15 | <el-option
|
16 |
| - v-for="item in options" |
| 16 | + v-for="item in options(revisionRightIndex)" |
17 | 17 | :key="item.value"
|
18 | 18 | :label="item.text"
|
19 | 19 | :value="item.value"
|
20 | 20 | />
|
21 | 21 | </el-select>
|
22 | 22 | <el-button-group>
|
23 |
| - <el-button :icon="FileCode" @click="seeRevision(revisionLeft, revisionLeftText)"> |
| 23 | + <el-button :icon="FileCode" @click="seeRevision(revisionLeftIndex, revisionLeftText)"> |
24 | 24 | <span class="d-none d-lg-inline-block"> {{ $t('see full revision') }}</span>
|
25 | 25 | </el-button>
|
26 |
| - <el-button :icon="Restore" :disabled="revisionNumber(revisionLeft) === flow.revision" @click="restoreRevision(revisionLeft, revisionLeftText)"> |
| 26 | + <el-button :icon="Restore" :disabled="revisionNumber(revisionLeftIndex) === flow.revision" @click="restoreRevision(revisionLeftIndex, revisionLeftText)"> |
27 | 27 | <span class="d-none d-lg-inline-block"> {{ $t('restore') }}</span>
|
28 | 28 | </el-button>
|
29 | 29 | </el-button-group>
|
30 | 30 | </div>
|
31 | 31 |
|
32 |
| - <el-alert v-if="revisionLeftError" type="warning" show-icon :closable="false" class="mb-0 mt-3"> |
33 |
| - <strong>{{ $t('invalid source') }}</strong><br> |
34 |
| - {{ revisionLeftError }} |
35 |
| - </el-alert> |
36 |
| - |
37 |
| - <crud class="mt-3" permission="FLOW" :detail="{namespace: $route.params.namespace, flowId: $route.params.id, revision: revisionNumber(revisionLeft)}" /> |
| 32 | + <crud class="mt-3" permission="FLOW" :detail="{namespace: $route.params.namespace, flowId: $route.params.id, revision: revisionNumber(revisionLeftIndex)}" /> |
38 | 33 | </el-col>
|
39 |
| - <el-col :span="12" v-if="revisionRight !== undefined"> |
| 34 | + <el-col :span="12" v-if="revisionRightIndex !== undefined"> |
40 | 35 | <div class="revision-select mb-3">
|
41 |
| - <el-select v-model="revisionRight"> |
| 36 | + <el-select v-model="revisionRightIndex" @change="addQuery"> |
42 | 37 | <el-option
|
43 |
| - v-for="item in options" |
| 38 | + v-for="item in options(revisionLeftIndex)" |
44 | 39 | :key="item.value"
|
45 | 40 | :label="item.text"
|
46 | 41 | :value="item.value"
|
47 | 42 | />
|
48 | 43 | </el-select>
|
49 | 44 | <el-button-group>
|
50 |
| - <el-button :icon="FileCode" @click="seeRevision(revisionRight, revisionRightText)"> |
| 45 | + <el-button :icon="FileCode" @click="seeRevision(revisionRightIndex, revisionRightText)"> |
51 | 46 | <span class="d-none d-lg-inline-block"> {{ $t('see full revision') }}</span>
|
52 | 47 | </el-button>
|
53 |
| - <el-button :icon="Restore" :disabled="revisionNumber(revisionRight) === flow.revision" @click="restoreRevision(revisionRight, revisionRightText)"> |
| 48 | + <el-button :icon="Restore" :disabled="revisionNumber(revisionRightIndex) === flow.revision" @click="restoreRevision(revisionRightIndex, revisionRightText)"> |
54 | 49 | <span class="d-none d-lg-inline-block"> {{ $t('restore') }}</span>
|
55 | 50 | </el-button>
|
56 | 51 | </el-button-group>
|
57 | 52 | </div>
|
58 | 53 |
|
59 |
| - <el-alert v-if="revisionRightError" type="warning" show-icon :closable="false" class="mb-0 mt-3"> |
60 |
| - <strong>{{ $t('invalid source') }}</strong><br> |
61 |
| - {{ revisionRightError }} |
62 |
| - </el-alert> |
63 |
| - |
64 |
| - <crud class="mt-3" permission="FLOW" :detail="{namespace: $route.params.namespace, flowId: $route.params.id, revision: revisionNumber(revisionRight)}" /> |
| 54 | + <crud class="mt-3" permission="FLOW" :detail="{namespace: $route.params.namespace, flowId: $route.params.id, revision: revisionNumber(revisionRightIndex)}" /> |
65 | 55 | </el-col>
|
66 | 56 | </el-row>
|
67 | 57 |
|
68 | 58 | <editor
|
69 | 59 | class="mt-1"
|
| 60 | + v-if="revisionLeftText && revisionRightText" |
70 | 61 | :diff-side-by-side="sideBySide"
|
71 | 62 | :model-value="revisionRightText"
|
72 | 63 | :original="revisionLeftText"
|
|
96 | 87 |
|
97 | 88 | <script>
|
98 | 89 | import {mapState} from "vuex";
|
99 |
| - import YamlUtils from "../../utils/yamlUtils"; |
100 | 90 | import Editor from "../../components/inputs/Editor.vue";
|
101 | 91 | import Crud from "override/components/auth/Crud.vue";
|
102 | 92 | import Drawer from "../Drawer.vue";
|
|
109 | 99 | },
|
110 | 100 | methods: {
|
111 | 101 | load() {
|
112 |
| - this.$store |
113 |
| - .dispatch("flow/loadRevisions", this.$route.params) |
114 |
| - .then(() => { |
115 |
| - const revisionLength = this.revisions.length; |
116 |
| - if (revisionLength > 0) { |
117 |
| - this.revisionRight = revisionLength - 1; |
118 |
| - } |
119 |
| - if (revisionLength > 1) { |
120 |
| - this.revisionLeft = revisionLength - 2; |
121 |
| - } |
122 |
| - if (this.$route.query.revisionRight) { |
123 |
| - this.revisionRight = this.revisionIndex( |
124 |
| - this.$route.query.revisionRight |
125 |
| - ); |
126 |
| - if ( |
127 |
| - !this.$route.query.revisionLeft && |
128 |
| - this.revisionRight > 0 |
129 |
| - ) { |
130 |
| - this.revisionLeft = this.revisions.length - 1; |
131 |
| - } |
132 |
| - } |
133 |
| - if (this.$route.query.revisionLeft) { |
134 |
| - this.revisionLeft = this.revisionIndex( |
135 |
| - this.$route.query.revisionLeft |
136 |
| - ); |
137 |
| - } |
138 |
| - }); |
| 102 | + const currentRevision = this.flow.revision; |
| 103 | +
|
| 104 | + this.revisions = [...Array(currentRevision).keys()].map(((k, i) => { |
| 105 | + if (currentRevision === this.revisionNumber(i)) { |
| 106 | + return this.flow; |
| 107 | + } |
| 108 | + return {revision: i + 1}; |
| 109 | + })); |
| 110 | +
|
| 111 | + if (this.$route.query.revisionRight) { |
| 112 | + this.revisionRightIndex = this.revisionIndex( |
| 113 | + this.$route.query.revisionRight |
| 114 | + ); |
| 115 | + if ( |
| 116 | + !this.$route.query.revisionLeft && |
| 117 | + this.revisionRightIndex > 0 |
| 118 | + ) { |
| 119 | + this.revisionLeftIndex = this.revisionRightIndex - 1; |
| 120 | + } |
| 121 | + } else if (currentRevision > 0) { |
| 122 | + this.revisionRightIndex = currentRevision - 1; |
| 123 | + } |
| 124 | +
|
| 125 | + if (this.$route.query.revisionLeft) { |
| 126 | + this.revisionLeftIndex = this.revisionIndex( |
| 127 | + this.$route.query.revisionLeft |
| 128 | + ); |
| 129 | + } else if (currentRevision > 1) { |
| 130 | + this.revisionLeftIndex = currentRevision - 2; |
| 131 | + } |
139 | 132 | },
|
140 | 133 | revisionIndex(revision) {
|
141 |
| - const rev = parseInt(revision); |
142 |
| - for (let i = 0; i < this.revisions.length; i++) { |
143 |
| - if (rev === this.revisions[i].revision) { |
144 |
| - return i; |
145 |
| - } |
| 134 | + const revisionInt = parseInt(revision); |
| 135 | +
|
| 136 | + if (revisionInt < 1 || revisionInt > this.revisions.length) { |
| 137 | + return undefined; |
146 | 138 | }
|
| 139 | +
|
| 140 | + return revisionInt - 1; |
147 | 141 | },
|
148 | 142 | revisionNumber(index) {
|
149 |
| - return this.revisions[index].revision; |
| 143 | + return index + 1; |
150 | 144 | },
|
151 | 145 | seeRevision(index, revision) {
|
152 | 146 | this.revisionId = index
|
|
167 | 161 | addQuery() {
|
168 | 162 | this.$router.push({query: {
|
169 | 163 | ...this.$route.query,
|
170 |
| - ...{revisionLeft:this.revisionLeft + 1, revisionRight: this.revisionRight + 1}} |
| 164 | + ...{revisionLeft:this.revisionLeftIndex + 1, revisionRight: this.revisionRightIndex + 1}} |
171 | 165 | });
|
172 | 166 | },
|
173 |
| - transformRevision(source) { |
174 |
| - if (source.exception) { |
175 |
| - return YamlUtils.stringify(YamlUtils.parse(source.source)); |
176 |
| - } |
| 167 | + async fetchRevision(revision) { |
| 168 | + const revisionFetched = await this.$store.dispatch("flow/loadFlow", { |
| 169 | + namespace: this.flow.namespace, |
| 170 | + id: this.flow.id, |
| 171 | + revision, |
| 172 | + allowDeleted: true, |
| 173 | + store: false |
| 174 | + }); |
| 175 | + this.revisions[this.revisionIndex(revision)] = revisionFetched; |
177 | 176 |
|
178 |
| - return source.source ? source.source : YamlUtils.stringify(source); |
| 177 | + return revisionFetched; |
| 178 | + }, |
| 179 | + options(excludeRevisionIndex) { |
| 180 | + return this.revisions |
| 181 | + .filter((_, index) => index !== excludeRevisionIndex) |
| 182 | + .map(({revision}) => ({value: this.revisionIndex(revision), text: revision})); |
179 | 183 | }
|
180 | 184 | },
|
181 | 185 | computed: {
|
182 |
| - ...mapState("flow", ["flow", "revisions"]), |
183 |
| - options() { |
184 |
| - return (this.revisions || []).map((revision, x) => { |
185 |
| - return { |
186 |
| - value: x, |
187 |
| - text: revision.revision, |
188 |
| - }; |
189 |
| - }); |
190 |
| - }, |
191 |
| - revisionLeftError() { |
192 |
| - if (this.revisionLeft === undefined) { |
193 |
| - return ""; |
| 186 | + ...mapState("flow", ["flow"]) |
| 187 | + }, |
| 188 | + watch: { |
| 189 | + revisionLeftIndex: async function (newValue, oldValue) { |
| 190 | + if (newValue === oldValue) { |
| 191 | + return; |
194 | 192 | }
|
195 | 193 |
|
196 |
| - return this.revisions[this.revisionLeft].exception |
197 |
| - }, |
198 |
| - revisionRightError() { |
199 |
| - if (this.revisionRight === undefined) { |
200 |
| - return ""; |
| 194 | + if (newValue === undefined) { |
| 195 | + this.revisionLeftText = undefined; |
201 | 196 | }
|
202 | 197 |
|
203 |
| - return this.revisions[this.revisionRight].exception |
204 |
| - }, |
205 |
| - revisionLeftText() { |
206 |
| - if (this.revisionLeft === undefined) { |
207 |
| - return ""; |
| 198 | + const leftRevision = this.revisions[newValue]; |
| 199 | + let source = leftRevision.source; |
| 200 | + if (!source) { |
| 201 | + source = (await this.fetchRevision(leftRevision.revision)).source; |
208 | 202 | }
|
209 | 203 |
|
210 |
| - return this.transformRevision(this.revisions[this.revisionLeft]); |
| 204 | + this.revisionLeftText = source; |
211 | 205 | },
|
212 |
| - revisionRightText() { |
213 |
| - if (this.revisionRight === undefined) { |
214 |
| - return ""; |
| 206 | + revisionRightIndex: async function (newValue, oldValue) { |
| 207 | + if (newValue === oldValue) { |
| 208 | + return; |
215 | 209 | }
|
216 | 210 |
|
217 |
| - return this.transformRevision(this.revisions[this.revisionRight]); |
218 |
| - }, |
| 211 | + if (newValue === undefined) { |
| 212 | + this.revisionRightText = undefined; |
| 213 | + } |
| 214 | +
|
| 215 | + const rightRevision = this.revisions[newValue]; |
| 216 | + let source = rightRevision.source; |
| 217 | + if (!source) { |
| 218 | + source = (await this.fetchRevision(rightRevision.revision)).source; |
| 219 | + } |
| 220 | +
|
| 221 | + this.revisionRightText = source; |
| 222 | + } |
219 | 223 | },
|
220 | 224 | data() {
|
221 | 225 | return {
|
222 |
| - revisionLeft: undefined, |
223 |
| - revisionRight: undefined, |
| 226 | + revisionLeftIndex: undefined, |
| 227 | + revisionRightIndex: undefined, |
| 228 | + revisionLeftText: undefined, |
| 229 | + revisionRightText: undefined, |
224 | 230 | revision: undefined,
|
| 231 | + revisions: [], |
225 | 232 | revisionId: undefined,
|
226 | 233 | revisionYaml: undefined,
|
227 | 234 | sideBySide: true,
|
|
0 commit comments