Vue.component('entity-editor', { data: function() { return { entity_pending: "", entity: "", components: {}, } }, methods: { entity_url(entity) { return entity.replace(/\./g, "/"); }, request_entity(entity) { if (!entity || !entity.length) { this.entity_pending = ""; this.entity = ""; this.components = {}; return; } this.entity_pending = entity; var entity_url = this.entity_url(entity); app.get("entity/" + entity_url, (msg) => { this.entity = this.entity_pending; this.components = msg; this.error = false; }, (Http) => { if (Http.status == 404) { // Entity can no longer be found on URL this.entity_pending = ""; this.entity = ""; this.components = {}; } }); }, select_entity(entity) { if (entity != this.entity) { this.entity_pending = entity; this.request_entity(entity); } }, entity_hidden() { if (this.entity) { return 'visible;'; } else { return 'hidden;'; } }, components_hidden() { if (this.components) { return 'visible;'; } else { return 'hidden;'; } }, e_add(event) { this.$emit('select-component', { callback: function(component) { app.put("entity/" + this.entity_url(this.entity) + "?select=" + component, undefined, (msg) => { this.request_entity(this.entity); }); }.bind(this) }); }, e_sync(event) { this.request_entity(this.entity); }, e_remove_component(event) { app.delete("entity/" + this.entity_url(this.entity) + "?select=" + event.component, undefined, (msg) => { this.request_entity(this.entity); }); }, e_delete(event) { app.delete("entity/" + this.entity_url(this.entity), undefined, (msg) => { this.request_entity(undefined); }); } }, computed: { tags: function() { var type = this.components.type; if (!type) { return []; } var data = this.components.data; var tags = []; for (var i = 0; i < type.length; i ++) { var tag = type[i]; if (!data.hasOwnProperty(tag)) { if (Array.isArray(tag)) { tags.push(type[i].join(" | ")); } else { tags.push(tag); } } } return tags; } }, template: `
{{ components.path }}
Tags
` });