UNPKG

json-object-editor

Version:

JOE the Json Object Editor | Platform Edition

132 lines (120 loc) 6.14 kB
var tag ={ title: '${name}', info:"Assign a tag to categorize different pieces of information so you can easily access information in a category in one place.", default_schema:true, // Curated summary for agents summary:{ description:'Categorization label applied across datasets; supports hierarchy.', purpose:'Tags classify records for search, filters, and reporting. A tag may have a parent tag (for hierarchy) and may apply to specific schemas via datasets. Many schemas reference tags (e.g., task, project, user).', labelField:'name', defaultSort:{ field:'name', dir:'asc' }, searchableFields:['name','info','tag_id','_id'], allowedSorts:['name','joeUpdated','created','tag_id'], relationships:{ outbound:[ { field:'parent_tag', targetSchema:'tag', cardinality:'one' }, { field:'datasets', targetSchema:'<schemaName>', cardinality:'many' } ], inbound:{ graphRef:'server/relationships.graph.json' } }, joeManagedFields:['created','joeUpdated'], fields:[ { name:'_id', type:'string', required:true }, { name:'itemtype', type:'string', required:true, const:'tag' }, { name:'name', type:'string', required:true }, { name:'info', type:'string' }, { name:'parent_tag', type:'string', isReference:true, targetSchema:'tag' }, { name:'tag_id', type:'string' }, { name:'datasets', type:'string', isArray:true }, { name:'joeUpdated', type:'string', format:'date-time', required:true }, { name:'created', type:'string', format:'date-time', required:true } ] }, fields:[ 'name', 'info', {name:'parent_tag',display:"Parent Tag", comment:'used for organizing tags',type:'select',values:'tag',idprop:'_id',blank:true, width:'50%'}, {name:'tag_id',display:'Tag ID',comment:'a memorable ID for this parent tag', width:'50%'}, 'datasets', {sidebar_start:'right'}, {section_start:'usage',collapsed:false}, {name:'usages',label:false,type:'content', run:function(item){ var usages = _joe.search({tags:{$in:[item._id]}}) var html = '<joe-title>'+usages.length+' objects use this tag</joe-title>'; usages.sortBy('itemtype,name').map(function(usage){ html += _joe.renderFieldListItem(usage,function(item){ var html = '<joe-full-right>' +'<joe-subtext>updated</joe-subtext>' +'<joe-subtitle>'+_joe.Utils.toDateString(item.joeUpdated)+'</joe-subtitle>' +'</joe-full-right>' +(_joe.schemas[usage.itemtype].menuicon && '<joe-icon class="icon-50 icon-grey fleft">' +_joe.schemas[usage.itemtype].menuicon+'</joe-icon>' || '') +'<joe-subtext>${itemtype}</joe-subtext>' +'<joe-subtitle>${name}</joe-subtitle><joe-subtext>${info}</joe-subtext>'; return html; },usage.itemtype); }); return html; }}, {section_end:'usage'}, {sidebar_end:'right'}, '_id','created','itemtype' ], idprop: '_id', itemExpander:function(tg){ //todo: return list of sub tags }, subsets:function(){ var schemas = []; var subs = []; _joe.current.list.map(function(tag){ schemas = schemas.concat(tag.datasets||[]); }); (new Set(schemas)).map(function(schema){ subs.push({name:schema,filter:{datasets:{$in:[schema]}}}) }); subs = subs.sortBy('name'); // subs = subs.concat(_joe.Filter.Options.getDatasetPropertyValues('tag','parent_tag',{ // group:'by parent tag', // display:'${name}', // })); return subs; }, menuicon:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="-200 -200 900 900"><rect x="101.7" y="183.8" transform="matrix(-0.7071 -0.7071 0.7071 -0.7071 264.6132 638.825)" width="325.9" height="161.6" class="a"/><path d="M491.2 310.4L309.1 128.3l-41.9-42 -50.8-50.8L7.4 0.2c-9.4-1.6-7.2 7.2-7.2 7.2l35.3 209 50.8 50.8 42 42 182.1 182.1c11.7 11.7 30.8 11.7 42.4 0L491.3 352.8C502.9 341.2 502.9 322.1 491.2 310.4zM53.7 73.2c-10.7 0-19.5-8.7-19.5-19.5C34.2 42.9 43 34.2 53.7 34.2 64.5 34.2 73.2 42.9 73.2 53.7 73.2 64.5 64.5 73.2 53.7 73.2zM322.7 456.9L72.4 206.5 206.5 72.4l250.3 250.3L322.7 456.9z" /></svg>', listView:{ title: function(tag){ // var datasets = tag.datasets.split(','); return '<joe-fright>${RUN[_joe.getDataItemProp;\'${parent_tag}\',\'tag\']}</joe-fright><joe-title>${name}</joe-title><joe-subtitle>${info}</joe-subtitle>'+ '<joe-subtext>${ENUM[${datasets}]}</joe-subtext>'; //+(datasets||''); }, listWindowTitle: 'Tags' }, methods:{ renderTags:function(tags,specs){ var html = '' var specs = specs || {}; if (typeof specs == 'string'){ specs = {cssclass:specs}; } //list the tags of an object, if array, use array if object, use the tags property //if no tags, return empty string var tags = tags.tags || tags; if(!tags || tags.length == 0){ return ''; } html += `<joe-tags class="${specs.cssclass||''}">`; tags.map(function(tag){ let tagObj = _joe.Cache.get(tag);//$J.get(tag); if(tagObj){ html+= `<joe-tag data-id="${tagObj._id}" title="${tagObj.info}" style="${tagObj.color && (`background:'${tagObj.color}'`)||''}">${tagObj.name}</joe-tag>`; } }) html+= '</joe-tags>'; return html; } } }; module.exports = tag;