2020-05-28 00:17:13 +02:00
|
|
|
import TabAwareWidget from "./tab_aware_widget.js";
|
2020-06-26 22:17:39 +02:00
|
|
|
import AttributeDetailWidget from "./attribute_detail.js";
|
2020-07-17 00:08:28 +02:00
|
|
|
import attributeRenderer from "../services/attribute_renderer.js";
|
|
|
|
import AttributeEditorWidget from "./attribute_editor.js";
|
2020-07-23 22:31:06 +02:00
|
|
|
import options from '../services/options.js';
|
2020-07-09 23:59:27 +02:00
|
|
|
|
2020-05-28 00:17:13 +02:00
|
|
|
const TPL = `
|
2020-07-16 23:12:10 +02:00
|
|
|
<div class="attribute-list">
|
2020-06-18 12:52:16 +02:00
|
|
|
<style>
|
2020-07-16 23:12:10 +02:00
|
|
|
.attribute-list {
|
2020-06-26 22:17:39 +02:00
|
|
|
margin-left: 7px;
|
|
|
|
margin-right: 7px;
|
|
|
|
}
|
2020-06-18 12:52:16 +02:00
|
|
|
|
2020-06-26 22:17:39 +02:00
|
|
|
.inherited-attributes {
|
|
|
|
color: var(--muted-text-color);
|
|
|
|
max-height: 200px;
|
|
|
|
overflow: auto;
|
2020-07-08 23:51:47 +02:00
|
|
|
padding-bottom: 5px;
|
2020-07-09 00:07:14 +02:00
|
|
|
padding-left: 7px;
|
2020-06-26 22:17:39 +02:00
|
|
|
}
|
|
|
|
|
2020-07-16 23:12:10 +02:00
|
|
|
.attribute-list-editor p {
|
2020-06-26 22:17:39 +02:00
|
|
|
margin: 0 !important;
|
|
|
|
}
|
|
|
|
|
2020-07-16 23:12:10 +02:00
|
|
|
.attribute-list.error .attribute-list-editor {
|
2020-06-26 22:17:39 +02:00
|
|
|
border-color: red !important;
|
|
|
|
}
|
2020-06-18 12:52:16 +02:00
|
|
|
|
2020-06-24 00:02:54 +02:00
|
|
|
.attr-expander {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
color: var(--muted-text-color);
|
|
|
|
font-size: small;
|
|
|
|
}
|
|
|
|
|
2020-07-16 23:12:10 +02:00
|
|
|
.attribute-list hr {
|
2020-06-24 00:02:54 +02:00
|
|
|
height: 1px;
|
|
|
|
border-color: var(--main-border-color);
|
|
|
|
position: relative;
|
|
|
|
top: 4px;
|
|
|
|
margin-top: 5px;
|
2020-06-24 23:56:39 +02:00
|
|
|
margin-bottom: 0;
|
2020-06-24 00:02:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
.attr-expander-text {
|
|
|
|
padding-left: 20px;
|
|
|
|
padding-right: 20px;
|
|
|
|
white-space: nowrap;
|
|
|
|
}
|
|
|
|
|
|
|
|
.attr-expander:hover {
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
.attr-expander:not(.error):hover hr {
|
|
|
|
border-color: black;
|
|
|
|
}
|
|
|
|
|
|
|
|
.attr-expander:not(.error):hover .attr-expander-text {
|
|
|
|
color: black;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
2020-06-24 23:56:39 +02:00
|
|
|
<div class="attr-expander attr-owned-expander">
|
2020-06-24 00:02:54 +02:00
|
|
|
<hr class="w-100">
|
|
|
|
|
2020-06-24 23:56:39 +02:00
|
|
|
<div class="attr-expander-text"></div>
|
2020-06-24 00:02:54 +02:00
|
|
|
|
|
|
|
<hr class="w-100">
|
|
|
|
</div>
|
|
|
|
|
2020-06-24 23:56:39 +02:00
|
|
|
<div class="attr-display">
|
2020-07-17 00:08:28 +02:00
|
|
|
<div class="attr-editor-placeholder"></div>
|
2020-06-24 23:56:39 +02:00
|
|
|
|
2020-06-27 00:40:35 +02:00
|
|
|
<hr class="w-100 attr-inherited-empty-expander" style="margin-bottom: 10px;">
|
2020-06-24 23:56:39 +02:00
|
|
|
|
|
|
|
<div class="attr-expander attr-inherited-expander">
|
|
|
|
<hr class="w-100">
|
|
|
|
|
2020-07-16 23:12:10 +02:00
|
|
|
<div class="attr-expander-text"></div>
|
2020-06-24 23:56:39 +02:00
|
|
|
|
|
|
|
<hr class="w-100">
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="inherited-attributes"></div>
|
|
|
|
</div>
|
|
|
|
|
2020-05-28 00:17:13 +02:00
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
|
2020-07-16 23:12:10 +02:00
|
|
|
export default class AttributeListWidget extends TabAwareWidget {
|
2020-05-28 00:17:13 +02:00
|
|
|
constructor() {
|
|
|
|
super();
|
2020-05-28 23:59:08 +02:00
|
|
|
|
2020-06-26 22:17:39 +02:00
|
|
|
this.attributeDetailWidget = new AttributeDetailWidget().setParent(this);
|
2020-07-17 23:55:59 +02:00
|
|
|
this.attributeEditorWidget = new AttributeEditorWidget(this.attributeDetailWidget).setParent(this);
|
2020-06-26 22:17:39 +02:00
|
|
|
|
2020-07-17 00:08:28 +02:00
|
|
|
this.child(this.attributeEditorWidget, this.attributeDetailWidget);
|
2020-05-28 00:17:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
doRender() {
|
|
|
|
this.$widget = $(TPL);
|
|
|
|
|
2020-06-24 23:56:39 +02:00
|
|
|
this.$attrDisplay = this.$widget.find('.attr-display');
|
2020-07-23 22:31:06 +02:00
|
|
|
this.$attrDisplay.toggle(options.is('attributeListExpanded'));
|
2020-06-24 23:56:39 +02:00
|
|
|
|
|
|
|
this.$ownedExpander = this.$widget.find('.attr-owned-expander');
|
2020-07-23 22:31:06 +02:00
|
|
|
this.$ownedExpander.on('click', async () => {
|
|
|
|
const collapse = this.$attrDisplay.is(":visible");
|
|
|
|
|
|
|
|
await options.save('attributeListExpanded', !collapse);
|
|
|
|
|
|
|
|
this.triggerEvent(`attributeListCollapsedStateChanged`, {collapse});
|
2020-06-24 23:56:39 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
this.$ownedExpanderText = this.$ownedExpander.find('.attr-expander-text');
|
|
|
|
|
|
|
|
this.$inheritedAttributes = this.$widget.find('.inherited-attributes');
|
|
|
|
|
|
|
|
this.$inheritedExpander = this.$widget.find('.attr-inherited-expander');
|
|
|
|
this.$inheritedExpander.on('click', () => {
|
|
|
|
if (this.$inheritedAttributes.is(":visible")) {
|
|
|
|
this.$inheritedAttributes.slideUp(200);
|
2020-06-24 00:02:54 +02:00
|
|
|
}
|
|
|
|
else {
|
2020-06-24 23:56:39 +02:00
|
|
|
this.$inheritedAttributes.slideDown(200);
|
2020-06-24 00:02:54 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-06-24 23:56:39 +02:00
|
|
|
this.$inheritedExpanderText = this.$inheritedExpander.find('.attr-expander-text');
|
|
|
|
|
|
|
|
this.$inheritedEmptyExpander = this.$widget.find('.attr-inherited-empty-expander');
|
2020-06-24 00:02:54 +02:00
|
|
|
|
2020-07-17 00:08:28 +02:00
|
|
|
this.$widget.find('.attr-editor-placeholder').replaceWith(this.attributeEditorWidget.render());
|
2020-06-26 22:17:39 +02:00
|
|
|
this.$widget.append(this.attributeDetailWidget.render());
|
2020-05-28 00:17:13 +02:00
|
|
|
}
|
|
|
|
|
2020-05-28 23:59:08 +02:00
|
|
|
async refreshWithNote(note) {
|
2020-07-23 22:31:06 +02:00
|
|
|
const ownedAttributes = note.getOwnedAttributes().filter(attr => !attr.isAutoLink);
|
2020-07-17 00:08:28 +02:00
|
|
|
|
|
|
|
this.$ownedExpanderText.text(ownedAttributes.length + ' owned ' + this.attrPlural(ownedAttributes.length));
|
2020-06-24 23:56:39 +02:00
|
|
|
|
2020-06-27 00:40:35 +02:00
|
|
|
const inheritedAttributes = note.getAttributes().filter(attr => attr.noteId !== this.noteId);
|
2020-07-04 00:20:23 +02:00
|
|
|
|
2020-06-27 00:40:35 +02:00
|
|
|
if (inheritedAttributes.length === 0) {
|
2020-06-24 23:56:39 +02:00
|
|
|
this.$inheritedExpander.hide();
|
|
|
|
this.$inheritedEmptyExpander.show();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.$inheritedExpander.show();
|
|
|
|
this.$inheritedEmptyExpander.hide();
|
|
|
|
}
|
|
|
|
|
2020-06-27 00:40:35 +02:00
|
|
|
this.$inheritedExpanderText.text(inheritedAttributes.length + ' inherited ' + this.attrPlural(inheritedAttributes.length));
|
2020-06-24 23:56:39 +02:00
|
|
|
|
2020-07-04 00:40:41 +02:00
|
|
|
this.$inheritedAttributes.empty();
|
|
|
|
|
2020-07-13 23:27:23 +02:00
|
|
|
await this.renderInheritedAttributes(inheritedAttributes, this.$inheritedAttributes);
|
2020-07-09 23:59:27 +02:00
|
|
|
}
|
|
|
|
|
2020-06-24 23:56:39 +02:00
|
|
|
attrPlural(number) {
|
|
|
|
return 'attribute' + (number === 1 ? '' : 's');
|
2020-05-28 23:59:08 +02:00
|
|
|
}
|
|
|
|
|
2020-07-13 23:27:23 +02:00
|
|
|
renderInheritedAttributes(attributes, $container) {
|
2020-07-05 23:53:55 +02:00
|
|
|
for (const attribute of attributes) {
|
|
|
|
const $span = $("<span>")
|
|
|
|
.on('click', e => this.attributeDetailWidget.showAttributeDetail({
|
|
|
|
attribute: {
|
|
|
|
noteId: attribute.noteId,
|
|
|
|
type: attribute.type,
|
|
|
|
name: attribute.name,
|
|
|
|
value: attribute.value
|
|
|
|
},
|
|
|
|
isOwned: false,
|
|
|
|
x: e.pageX,
|
|
|
|
y: e.pageY
|
|
|
|
}));
|
|
|
|
|
|
|
|
$container.append($span);
|
|
|
|
|
2020-07-17 00:08:28 +02:00
|
|
|
attributeRenderer.renderAttribute(attribute, $span, false);
|
2020-06-18 22:28:18 +02:00
|
|
|
}
|
2020-07-09 23:59:27 +02:00
|
|
|
}
|
2020-07-17 23:55:59 +02:00
|
|
|
|
2020-07-23 00:19:50 +02:00
|
|
|
async saveAttributesCommand() {
|
|
|
|
await this.attributeEditorWidget.save();
|
|
|
|
}
|
|
|
|
|
2020-07-17 23:55:59 +02:00
|
|
|
updateAttributeListCommand({attributes}) {
|
|
|
|
this.attributeEditorWidget.updateAttributeList(attributes);
|
|
|
|
}
|
2020-07-23 22:31:06 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This event is used to synchronize collapsed state of all the tab-cached widgets since they are all rendered
|
|
|
|
* separately but should behave uniformly for the user.
|
|
|
|
*/
|
|
|
|
attributeListCollapsedStateChangedEvent({collapse}) {
|
|
|
|
if (collapse) {
|
|
|
|
this.$attrDisplay.slideUp(200);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.$attrDisplay.slideDown(200);
|
|
|
|
}
|
|
|
|
}
|
2020-05-28 00:17:13 +02:00
|
|
|
}
|