Skip to content

Commit

Permalink
aotf: associate mutations with cylc objects
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver-sanders committed Dec 4, 2020
1 parent 4366457 commit e7a3fbe
Show file tree
Hide file tree
Showing 5 changed files with 490 additions and 22 deletions.
138 changes: 138 additions & 0 deletions src/components/cylc/cylcObject/CylcObject.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<!--
Copyright (C) NIWA & British Crown (Met Office) & Contributors.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->

<template>
<div class="c-mutation">
<!--<v-tooltip bottom>-->
<!-- <template v-slot:activator="{ on, attrs }">-->
<!-- <span v-bind="attrs" v-on="on">-->
<!-- <slot></slot>-->
<!-- </span>-->
<!-- </template>-->
<!-- <div>-->
<!-- <span>{{type}}</span>-->
<!-- </div>-->
<!--</v-tooltip>-->
<v-menu offset-y>
<template v-slot:activator="{ on, attrs }">
<span v-bind="attrs" v-on="on">
<slot></slot>
</span>
</template>
<v-list>
<v-subheader>{{id}}</v-subheader>
<v-list-item-group v-model="mutation" color="primary">
<!--<pre>{{this.$workflowService.mutations}}</pre>-->

<v-list-item two-line
v-for="mutation in mutations"
:key="mutation.name"
@click="mutate(mutation)"
>
<v-list-item-content>
<!--<v-list-item-icon>-->
<!-- [> TODO <]-->
<!-- <v-icon></v-icon>-->
<!--</v-list-item-icon>-->
<v-list-item-title>
<span>{{mutation.title}}</span>
</v-list-item-title>
<v-list-item-subtitle>
<span>{{mutation.description}}</span>
</v-list-item-subtitle>
<!--<v-list-item-action>-->
<!-- <v-btn rounded color="primary" dark>Foo</v-btn>-->
<!--</v-list-item-action>-->
</v-list-item-content>
</v-list-item>
</v-list-item-group>
</v-list>
</v-menu>
</div>
</template>

<script>
import {
tokenise,
getType
} from './index'

import {
filterAssociations
// tokensToArgs
} from '@/services/mutation'

import { constructMutation } from '@/utils/graphql'

export default {
name: 'CylcObject',

props: {
id: {
type: String,
required: true
}
},

data () {
return {
mutation: null
}
},

computed: {
tokens () {
return tokenise(this.id)
},
type () {
return getType(this.tokens)
},
mutations () {
// TODO - this gets computed on load which is bad
return filterAssociations(
this.type,
this.tokens,
this.$workflowService.mutations
)[0]
}
},

methods: {
args (mutation) {
const argspec = {}
for (const arg of mutation.args) {
for (const token in this.tokens) {
if (arg.cylcObject && arg.cylcObject === token) {
if (arg.multiple) {
argspec[arg.name] = [this.tokens[token]]
} else {
argspec[arg.name] = this.tokens[token]
}
}
}
}
return argspec
},
mutate (mutation) {
console.log(`% ${mutation.title}`)
console.log(this.args(mutation))
const mutilation = constructMutation(mutation.gqlMutation)
console.log(mutilation)
}
}
}
</script>
84 changes: 84 additions & 0 deletions src/components/cylc/cylcObject/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* Copyright (C) NIWA & British Crown (Met Office) & Contributors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

const cylcObjects = Object.freeze({
User: 'user',
Workflow: 'workflow',
CyclePoint: 'cycle point',
Namespace: 'namespace',
// Task: 'task',
Job: 'job'
})

const identifierOrder = [
cylcObjects.User,
cylcObjects.Workflow,
cylcObjects.CyclePoint,
cylcObjects.Namespace,
// cylcObjects.Task,
cylcObjects.Job
]

const mutationMapping = {
// object: [[typeName: String, impliesMultiple: Boolean]]
workflow: [
['WorkflowID', false]
],
'cycle point': [
['CyclePoint', false],
['CyclePointGlob', true]
],
namespace: [
['NamespaceName', false],
['NamespaceIDGlob', true]
],
task: [
['TaskID', false]
],
job: [
['JobID', false]
]
}

function tokenise (id) {
id = id.split('|')
const ret = {}
for (let ind = 0; ind < id.length; ind++) {
ret[identifierOrder[ind]] = id[ind]
}
return ret
}

function getType (tokens) {
let last = null
let item = null
for (const key of identifierOrder) {
item = tokens[key]
if (!item) {
break
}
last = key
}
return last
}

export {
cylcObjects,
tokenise,
getType,
mutationMapping
}
54 changes: 32 additions & 22 deletions src/components/cylc/tree/TreeItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,42 +32,50 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<!-- the node value -->
<!-- TODO: revisit these values that can be replaced by constants later (and in other components too). -->
<div :class="getNodeDataClass()" @click="nodeClicked" v-if="node.type === 'cyclepoint'">
<task
:status="node.node.state"
:isHeld="node.node.isHeld"
:progress=0
/>
<CylcObject :id="node.node.id">
<task
:status="node.node.state"
:isHeld="node.node.isHeld"
:progress=0
/>
</CylcObject>
<span class="mx-1">{{ node.node.name }}</span>
</div>
<div :class="getNodeDataClass()" @click="nodeClicked" v-else-if="node.type === 'family-proxy'">
<task
:status="node.node.state"
:isHeld="node.node.isHeld"
:progress="node.node.progress"
/>
<CylcObject :id="node.node.id">
<task
:status="node.node.state"
:isHeld="node.node.isHeld"
:progress="node.node.progress"
/>
</CylcObject>
<span class="mx-1">{{ node.node.name }}</span>
</div>
<div :class="getNodeDataClass()" @click="nodeClicked" v-else-if="node.type === 'task-proxy'">
<task
:status="node.node.state"
:isHeld="node.node.isHeld"
:progress="node.node.progress"
/>
<CylcObject :id="node.node.id">
<task
:status="node.node.state"
:isHeld="node.node.isHeld"
:progress="node.node.progress"
/>
</CylcObject>
<span class="mx-1">{{ node.node.name }}</span>
<div v-if="!isExpanded" class="node-summary">
<!-- Task summary -->
<job
<CylcObject
v-for="(task, index) in node.children"
:id="task.id"
:key="`${task.id}-summary-${index}`"
:status="task.node.state"
/>
>
<job :status="task.node.state" />
</CylcObject>
</div>
</div>
<div :class="getNodeDataClass()" v-else-if="node.type === 'job'">
<div :class="getNodeDataClass()" @click="jobNodeClicked">
<job
:status="node.node.state"
/>
<CylcObject :id="node.node.id">
<job :status="node.node.state" />
</CylcObject>
<span class="mx-1">#{{ node.node.submitNum }}</span>
<span class="grey--text">{{ node.node.host }}</span>
</div>
Expand Down Expand Up @@ -108,6 +116,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

<script>
import Task from '@/components/cylc/Task'
import CylcObject from '@/components/cylc/cylcObject/CylcObject'
import Job from '@/components/cylc/Job'
import { treeitem } from '@/mixins/treeitem'

Expand All @@ -124,7 +133,8 @@ export default {
],
components: {
task: Task,
job: Job
job: Job,
CylcObject: CylcObject
},
props: {
node: {
Expand Down
Loading

0 comments on commit e7a3fbe

Please sign in to comment.