Skip to content

Commit 7fdee92

Browse files
committed
£tidy
1 parent 21b773b commit 7fdee92

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

src/components/cylc/cylcObject/Menu.vue

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
5959
<v-list-item
6060
v-for="{ mutation, requiresInfo, authorised } in displayMutations"
6161
:key="mutation.name"
62-
:disabled="!authorised"
62+
:disabled="isDisabled(mutation, authorised)"
6363
@click.stop="enact(mutation, requiresInfo)"
6464
class="c-mutation"
6565
>
6666
<v-list-item-avatar>
67-
<v-icon :disabled="!authorised" large>
67+
<v-icon :disabled="isDisabled(mutation, authorised)" large>
6868
{{ mutation._icon }}
6969
</v-icon>
7070
</v-list-item-avatar>
@@ -232,12 +232,18 @@ export default {
232232
233233
methods: {
234234
isEditable (authorised, mutation) {
235-
if (!authorised || mutation.name === 'log') {
235+
if (mutation.name === 'log' || this.isDisabled(mutation, authorised)) {
236236
return true
237237
} else {
238238
return false
239239
}
240240
},
241+
isDisabled (mutation, authorised) {
242+
if (((mutation._validStates.indexOf(this.node.node.status)) === -1) || !authorised) {
243+
return true
244+
}
245+
return false
246+
},
241247
openDialog (mutation) {
242248
if (mutation.name === 'log') {
243249
this.showMenu = false

src/utils/aotf.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,30 @@ export function processMutations (mutations, types) {
432432
mutation._icon = mutationIcons[mutation.name] || mutationIcons['']
433433
mutation._shortDescription = getMutationShortDesc(mutation.description)
434434
mutation._help = getMutationExtendedDesc(mutation.description)
435+
mutation._validStates = getStates(mutation.description)
435436
processArguments(mutation, types)
436437
}
437438
}
439+
/**
440+
* Get the workflow states that the mutation is valid for.
441+
*
442+
* @export
443+
* @param {string=} text - Full mutation description.
444+
* @return {Array<String>}
445+
*/
446+
export function getStates (text) {
447+
const defaultStates = ['running', 'paused', 'stopping', 'stopped']
448+
if (!text) {
449+
return defaultStates
450+
}
451+
const re = /Valid\sfor:\s(.*)\sworkflows./
452+
// default to all workflow states
453+
const validStates = text.match(re)
454+
if (validStates) {
455+
return validStates[1]
456+
}
457+
return defaultStates
458+
}
438459

439460
/**
440461
* Get the first part of a mutation description (up to the first double newline).

tests/unit/utils/aotf.spec.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,16 @@ describe('aotf (Api On The Fly)', () => {
6363
it('should add computed fields', () => {
6464
const input = {
6565
name: 'fooBar',
66-
description: 'Short description.\n\nLong\ndescription.',
66+
description: 'Short description.\n\nLong\ndescription.\nValid for: [\'stopped\'] workflows.',
6767
args: []
6868
}
6969
const output = {
7070
...input,
7171
_title: 'Foo Bar',
7272
_icon: aotf.mutationIcons[''],
7373
_shortDescription: 'Short description.',
74-
_help: 'Long\ndescription.'
74+
_help: 'Long\ndescription.\nValid for: [\'stopped\'] workflows.',
75+
_validStates: "['stopped']"
7576
}
7677
aotf.processMutations([input], null)
7778
expect(input).to.deep.equal(output)

0 commit comments

Comments
 (0)