-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
aotf: associate mutations with cylc objects
- Loading branch information
1 parent
4366457
commit e7a3fbe
Showing
5 changed files
with
490 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.