Finalize treatment of initial criterion
diff --git a/public/js/spec/vcSpec.js b/public/js/spec/vcSpec.js
index c532d32..5f7d3ad 100644
--- a/public/js/spec/vcSpec.js
+++ b/public/js/spec/vcSpec.js
@@ -728,6 +728,55 @@
}
]
});
+
+ var demoFactory = buildFactory(KorAP.VirtualCollection, {
+ "@type":"korap:docGroup",
+ "operation":"operation:or",
+ "operands":[
+ {
+ "@type":"korap:docGroup",
+ "operation":"operation:and",
+ "operands":[
+ {
+ "@type":"korap:doc",
+ "key":"Titel",
+ "value":"Baum",
+ "match":"match:eq"
+ },
+ {
+ "@type":"korap:doc",
+ "key":"Veröffentlichungsort",
+ "value":"hihi",
+ "match":"match:eq"
+ },
+ {
+ "@type":"korap:docGroup",
+ "operation":"operation:or",
+ "operands":[
+ {
+ "@type":"korap:doc",
+ "key":"Titel",
+ "value":"Baum",
+ "match":"match:eq"
+ },
+ {
+ "@type":"korap:doc",
+ "key":"Veröffentlichungsort",
+ "value":"hihi",
+ "match":"match:eq"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "@type":"korap:doc",
+ "key":"Untertitel",
+ "value":"huhu",
+ "match":"match:eq"
+ }
+ ]
+ });
it('should be initializable', function () {
var vc = KorAP.VirtualCollection.render();
@@ -945,6 +994,30 @@
'author = "Max Birkendale" | title = "Der Birnbaum" | pubDate in 2014-12-05'
);
});
+
+ it('should be reducible to unspecification', function () {
+ var vc = demoFactory.create();
+
+ expect(vc.toString()).toEqual(vc.root().toString());
+
+ expect(vc.toString()).toEqual('(Titel = "Baum" & Veröffentlichungsort = "hihi" & (Titel = "Baum" | Veröffentlichungsort = "hihi")) | Untertitel = "huhu"');
+
+ expect(vc.root().element().lastChild.children[0].firstChild.nodeValue).toEqual('and');
+ expect(vc.root().element().lastChild.children[1].firstChild.nodeValue).toEqual('×');
+
+ expect(vc.root().delOperand(vc.root().getOperand(0)).update()).not.toBeUndefined();
+
+ expect(vc.toString()).toEqual('Untertitel = "huhu"');
+
+ expect(vc.root().element().lastChild.children[0].firstChild.nodeValue).toEqual('and');
+ expect(vc.root().element().lastChild.children[1].firstChild.nodeValue).toEqual('or');
+ expect(vc.root().element().lastChild.children[2].firstChild.nodeValue).toEqual('×');
+
+ // Clean everything
+ vc.clean();
+ expect(vc.toString()).toEqual('⋯');
+
+ });
});
describe('KorAP.Operators', function () {
diff --git a/public/js/src/vc.js b/public/js/src/vc.js
index 03911ce..290531a 100644
--- a/public/js/src/vc.js
+++ b/public/js/src/vc.js
@@ -50,6 +50,27 @@
node.removeChild(node.firstChild);
};
+
+ // Add 'or'-criterion
+ KorAP._or = function (e) {
+ var obj = this.parentNode.refTo;
+ };
+
+
+ // Add 'and'-criterion
+ KorAP._and = function (e) {
+ var obj = this.parentNode.refTo;
+ };
+
+ // Remove doc or docGroup
+ KorAP._delete = function (e) {
+ var obj = this.parentNode.refTo;
+ if (obj.parent().ldType() !== null)
+ obj.parent().delOperand(obj).update();
+ else
+ obj.parent().clean();
+ };
+
KorAP.VirtualCollection = {
ldType : function () {
return null;
@@ -57,6 +78,13 @@
create : function () {
return Object.create(KorAP.VirtualCollection);
},
+ clean : function () {
+ if (this._root.ldType() !== "non") {
+ this._root.destroy();
+ this.root(KorAP.UnspecifiedDoc.create(this));
+ };
+ return this;
+ },
render : function (json) {
var obj = Object.create(KorAP.VirtualCollection);
@@ -129,19 +157,6 @@
}
};
- KorAP._or = function (e) {
- var obj = this.parentNode.refTo;
- };
-
- KorAP._and = function (e) {
- var obj = this.parentNode.refTo;
- };
-
- KorAP._delete = function (e) {
- var obj = this.parentNode.refTo;
- obj.parent().delOperand(obj).update();
- };
-
/**
* Operators for criteria
*/
@@ -239,7 +254,7 @@
* Unspecified criterion
*/
KorAP.UnspecifiedDoc = {
- _ldType : "doc",
+ _ldType : "non",
create : function (parent) {
var obj = Object.create(KorAP.JsonLD).
upgradeTo(KorAP.UnspecifiedDoc);
@@ -250,6 +265,7 @@
return obj;
},
update : function () {
+
if (this._element === undefined)
return this.element();
@@ -357,9 +373,7 @@
var op = this.operators(
true,
true,
- // No delete object, if this is the root
- (this._parent !== undefined &&
- this.parent().ldType() !== null) ? true : false
+ true
);
// Append new operators