[Debtags-commits] [svn] r1978 - in web/trunk: . js

Enrico Zini enrico at costa.debian.org
Mon Oct 2 19:03:52 UTC 2006


Author: enrico
Date: Mon Oct  2 19:03:52 2006
New Revision: 1978

Added:
   web/trunk/js/updatevoc   (contents, props changed)
Modified:
   web/trunk/js/debtags.js
   web/trunk/js/test.html
   web/trunk/main.css
Log:
Use pointer instead of crosshair cursor over selectable tags
Implemented vocabulary support in debtags.js
Added vocabulary upload script
Implemented all tag view in editor
Implemented adding and removing tags in editor


Modified: web/trunk/js/debtags.js
==============================================================================
--- web/trunk/js/debtags.js	(original)
+++ web/trunk/js/debtags.js	Mon Oct  2 19:03:52 2006
@@ -238,6 +238,13 @@
 		this.each(function(i){res.add(i);});
 		return res;
 	},
+	/*
+	filtervoc: function(voc) {
+		var voc1 = new Vocabulary();
+		// TODO: return a vocabulary with only those tags in voc that are also in
+		// this tagset
+	}
+	*/
 };
 
 Collection = function() {
@@ -327,6 +334,110 @@
 	},
 };
 
+Vocabulary = function(fdata, tdata) {
+	this.facs = fdata;
+	this.tags = tdata;
+	this.ftags = {};
+	for (var i in this.tags) {
+		var tmp = i.split("::");
+		if (! this.ftags.hasOwnProperty(tmp[0]))
+			this.ftags[tmp[0]] = new Tagset();
+		this.ftags[tmp[0]].add(i);
+	}
+};
+Vocabulary.prototype = {
+	// Return an array [shortdesc, longdesc]
+	facData: function(fac) {
+		return this.facs[fac];
+	},
+	// Return an array [shortdesc, longdesc]
+	tagData: function(tag) {
+		return this.tags[tag];
+	},
+	tagsOfFacet: function(fac) {
+		return this.ftags[fac];
+	},
+	eachFacet: function(fun) {
+		for (var i in this.facs) {
+			fun(i, this.facs[i][0], this.facs[i][1]);
+		}
+	},
+	eachTag: function(fun) {
+		for (var i in this.tags) {
+			fun(i, this.tags[i][0], this.tags[i][1]);
+		}
+	},
+	eachTagOfFacet: function(fac, fun) {
+		var ts = this.tagsOfFacet(fac);
+		var tmp = this;
+		if (ts) ts.each(function(t){
+			fun(t, tmp.tags[t][0], tmp.tags[t][1]);
+		});
+	},
+};
+
+/*
+
+// Define classes and instances for a global tag vocabulary
+function extractFacet(tag)
+{
+	return tag.slice(0, tag.indexOf("::"));
+}
+
+function Facet(name, sdesc, ldesc)
+{
+	this.name = name;
+	this.sdesc = sdesc;
+	this.ldesc = ldesc;
+	this.tags = new Array();
+}
+Facet.prototype.add = function(tag) {
+	this.tags.push(tag);
+	this[tag.name] = tag;
+}
+
+function Tag(name, sdesc, ldesc)
+{
+	this.name = name;
+	this.sdesc = sdesc;
+	this.ldesc = ldesc;
+}
+
+function Vocabulary()
+{
+	this.facets = new Array();
+}
+Vocabulary.prototype.add = function(facet) {
+	this.facets.push(facet);
+	this[facet.name] = facet;
+}
+Vocabulary.prototype.get = function(name) {
+	return this[name];
+}
+Vocabulary.prototype.getTag = function(name) {
+	
+	return this[extractFacet(name)][name];
+}
+
+var voc = new Vocabulary();
+
+*/
+
+function render(id, content)
+{
+	var node = document.getElementById(id);
+	node.innerHTML = content;
+}
+
+function setVisible(id, visible)
+{
+	var node = document.getElementById(id);
+	if (visible)
+		node.style.display = "block";
+	else
+		node.style.display = "none";
+}
+
 
 var wanted = new Tagset();
 var unwanted = new Tagset();

Modified: web/trunk/js/test.html
==============================================================================
--- web/trunk/js/test.html	(original)
+++ web/trunk/js/test.html	Mon Oct  2 19:03:52 2006
@@ -117,6 +117,40 @@
 t.add("antani", "blinda la supercazzola");
   ensure_equals("get description", t.get("antani"), "blinda la supercazzola");
 
+beginTest("Vocabulary");
+var fdata = { "use": ["short use", "long use"], "has": ["short has", "long has"] };
+var tdata = {
+	"use::a": ["use a", "long use a"],
+	"use::b": ["use b", "long use b"],
+	"has::1": ["has 1", "long has 1"],
+	"has::2": ["has 2", "long has 2"]
+};
+var t = new Vocabulary(fdata, tdata);
+  ensure_equals("short desc use", t.facData("use")[0], "short use");
+  ensure_equals("long desc use", t.facData("use")[1], "long use");
+  ensure_equals("short desc has", t.facData("has")[0], "short has");
+  ensure_equals("long desc has", t.facData("has")[1], "long has");
+
+  ensure_equals("short desc a", t.tagData("use::a")[0], "use a");
+  ensure_equals("long desc a", t.tagData("use::a")[1], "long use a");
+  ensure_equals("short desc b", t.tagData("use::b")[0], "use b");
+  ensure_equals("long desc b", t.tagData("use::b")[1], "long use b");
+  ensure_equals("short desc 1", t.tagData("has::1")[0], "has 1");
+  ensure_equals("long desc 1", t.tagData("has::1")[1], "long has 1");
+  ensure_equals("short desc 2", t.tagData("has::2")[0], "has 2");
+  ensure_equals("long desc 2", t.tagData("has::2")[1], "long has 2");
+var tt = t.tagsOfFacet("use");
+  ensure_equals("use has 2 tags", tt.size(), 2);
+var count = 0;
+t.eachFacet(function(f,s,l){++count;});
+  ensure_equals("facet iter", count, 2);
+count = 0;
+t.eachTag(function(t,s,l){++count;});
+  ensure_equals("tag iter", count, 4);
+count = 0;
+t.eachTagOfFacet("use", function(t,s,l){++count;});
+  ensure_equals("tag of facet iter", count, 2);
+
 beginTest("Queries");
 var progressCount = 0;
 var t = null;

Modified: web/trunk/main.css
==============================================================================
--- web/trunk/main.css	(original)
+++ web/trunk/main.css	Mon Oct  2 19:03:52 2006
@@ -86,7 +86,30 @@
 }
 
 #tags ul li span {
-	cursor: crosshair;
+	cursor: pointer;
 	text-decoration: underline;
-  color: brown;
+	color: brown;
+}
+
+/* Tag editor */
+
+.facet {
+	text-decoration: underline;
+	color: brown;
+	cursor: pointer;
+}
+
+.tag {
+	text-decoration: underline;
+	color: brown;
+	cursor: pointer;
+}
+
+#atfacets {
+	float: right;
+	width: 33%;
+}
+#attags li p {
+	margin: 0;
+	padding: 0;
 }



More information about the Debtags-commits mailing list