X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/37860134053cda88c7ee3a3f4300e949cad016f5..e17cd76f84c85ea408bf727165b713ca8de2ace5:/apps/workbench/app/assets/javascripts/components/edit_tags.js diff --git a/apps/workbench/app/assets/javascripts/components/edit_tags.js b/apps/workbench/app/assets/javascripts/components/edit_tags.js index 6294bd1c4b..1fddb2651e 100644 --- a/apps/workbench/app/assets/javascripts/components/edit_tags.js +++ b/apps/workbench/app/assets/javascripts/components/edit_tags.js @@ -4,7 +4,7 @@ window.SimpleInput = { view: function(vnode) { - return m("input.form-control", { + return m('input.form-control', { style: { width: '100%', }, @@ -22,7 +22,7 @@ window.SimpleInput = { window.SelectOrAutocomplete = { view: function(vnode) { - return m("input.form-control", { + return m('input.form-control', { style: { width: '100%' }, @@ -35,7 +35,9 @@ window.SelectOrAutocomplete = { vnode.state.awesomplete = new Awesomplete(vnode.dom, { list: vnode.attrs.options, minChars: 0, + maxItems: 1000000, autoFirst: true, + sort: false, }) vnode.state.create = vnode.attrs.create vnode.state.options = vnode.attrs.options @@ -85,9 +87,9 @@ window.TagEditorRow = { valueOpts = vnode.attrs.vocabulary().tags[vnode.attrs.name()].values } } - return m("tr", [ + return m('tr', [ // Erase tag - m("td", [ + m('td', [ vnode.attrs.editMode && m('div.text-center', m('a.btn.btn-default.btn-sm', { style: { @@ -97,13 +99,13 @@ window.TagEditorRow = { }, m('i.fa.fa-fw.fa-trash-o'))) ]), // Tag key - m("td", [ + m('td', [ vnode.attrs.editMode ? - m("div", {key: 'key'}, [ + m('div', {key: 'key'}, [ m(inputComponent, { options: nameOpts, value: vnode.attrs.name, - // Allow any tag name unless "strict" is set to true. + // Allow any tag name unless 'strict' is set to true. create: !vnode.attrs.vocabulary().strict, placeholder: 'key', }) @@ -111,9 +113,9 @@ window.TagEditorRow = { : vnode.attrs.name ]), // Tag value - m("td", [ + m('td', [ vnode.attrs.editMode ? - m("div", {key: 'value'}, [ + m('div', {key: 'value'}, [ m(inputComponent, { options: valueOpts, value: vnode.attrs.value, @@ -135,20 +137,20 @@ window.TagEditorRow = { window.TagEditorTable = { view: function(vnode) { - return m("table.table.table-condensed.table-justforlayout", [ - m("colgroup", [ - m("col", {width:"5%"}), - m("col", {width:"25%"}), - m("col", {width:"70%"}), + return m('table.table.table-condensed.table-justforlayout', [ + m('colgroup', [ + m('col', {width:'5%'}), + m('col', {width:'25%'}), + m('col', {width:'70%'}), ]), - m("thead", [ - m("tr", [ - m("th"), - m("th", "Key"), - m("th", "Value"), + m('thead', [ + m('tr', [ + m('th'), + m('th', 'Key'), + m('th', 'Value'), ]) ]), - m("tbody", [ + m('tbody', [ vnode.attrs.tags.length > 0 ? vnode.attrs.tags.map(function(tag, idx) { return m(TagEditorRow, { @@ -163,7 +165,7 @@ window.TagEditorTable = { vocabulary: vnode.attrs.vocabulary }) }) - : m("tr", m("td[colspan=3]", m("center", "Loading tags..."))) + : m('tr', m('td[colspan=3]', m('center', 'Loading tags...'))) ]), ]) } @@ -176,32 +178,25 @@ window.TagEditorApp = { var tag = {name: m.stream(name), value: m.stream(value), rowKey: uniqueID++} vnode.state.tags.push(tag) // Set dirty flag when any of name/value changes to non empty string - tag.name.map(function(v) { - if (v !== '') { - vnode.state.dirty(true) - } - }) - tag.value.map(function(v) { - if (v !== '') { - vnode.state.dirty(true) - } - }) + tag.name.map(function() { vnode.state.dirty(true) }) + tag.value.map(function() { vnode.state.dirty(true) }) tag.name.map(m.redraw) }, oninit: function(vnode) { vnode.state.sessionDB = new SessionDB() // Get vocabulary - vnode.state.vocabulary = m.stream({"strict":false, "tags":{}}) - m.request('/vocabulary.json').then(vnode.state.vocabulary) + vnode.state.vocabulary = m.stream({'strict':false, 'tags':{}}) + var vocabularyTimestamp = parseInt(Date.now() / 300000) // Bust cache every 5 minutes + m.request('/vocabulary.json?v=' + vocabularyTimestamp).then(vnode.state.vocabulary) vnode.state.editMode = vnode.attrs.targetEditable vnode.state.tags = [] vnode.state.dirty = m.stream(false) vnode.state.dirty.map(m.redraw) - vnode.state.objPath = '/arvados/v1/'+vnode.attrs.targetController+'/'+vnode.attrs.targetUuid + vnode.state.objPath = 'arvados/v1/' + vnode.attrs.targetController + '/' + vnode.attrs.targetUuid // Get tags vnode.state.sessionDB.request( vnode.state.sessionDB.loadLocal(), - '/arvados/v1/'+vnode.attrs.targetController, + 'arvados/v1/' + vnode.attrs.targetController, { data: { filters: JSON.stringify([['uuid', '=', vnode.attrs.targetUuid]]), @@ -213,6 +208,9 @@ window.TagEditorApp = { Object.keys(o.properties).forEach(function(k) { vnode.state.appendTag(vnode, k, o.properties[k]) }) + if (vnode.state.editMode) { + vnode.state.appendTag(vnode, '', '') + } // Data synced with server, so dirty state should be false vnode.state.dirty(false) // Add new tag row when the last one is completed @@ -230,22 +228,23 @@ window.TagEditorApp = { view: function(vnode) { return [ vnode.state.editMode && - m("div.pull-left", [ - m("a.btn.btn-primary.btn-sm"+(vnode.state.dirty() ? '' : '.disabled'), { + m('div.pull-left', [ + m('a.btn.btn-primary.btn-sm' + (vnode.state.dirty() ? '' : '.disabled'), { style: { margin: '10px 0px' }, onclick: function(e) { var tags = {} vnode.state.tags.forEach(function(t) { - if (t.name() != '' && t.value() != '') { + // Only ignore tags with empty key + if (t.name() != '') { tags[t.name()] = t.value() } }) vnode.state.sessionDB.request( vnode.state.sessionDB.loadLocal(), vnode.state.objPath, { - method: "PUT", + method: 'PUT', data: {properties: JSON.stringify(tags)} } ).then(function(v) {