1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
const Endless = imports.gi.Endless;
const GObject = imports.gi.GObject;
const Lang = imports.lang;
GObject.ParamFlags.READWRITE = GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE;
const ArticleModel = new Lang.Class({
Name: "ArticleModel",
Extends: GObject.Object,
Properties: {
'title': GObject.ParamSpec.string('title', 'Article Title', 'Human Readable Article Title',
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
""),
'source': GObject.ParamSpec.string('source', 'Source',
'Source website or database that the article is from',
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
''),
'uri': GObject.ParamSpec.string('uri', 'Article URI', 'Title URI as stored in wikipedia database',
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
"")
},
_init: function(params) {
this._categoryList = [];
this.parent(params);
},
/**
* Method: setCategories
* Give this article a list of categories or tags
*
* Parameters:
* categoryList - an array of strings signifying category IDs
*
* Makes this article's categories the list signified by _categoryList_,
* wiping out any categories that were previously set.
*/
setCategories: function (categoryList) {
this._categoryList = categoryList;
},
/**
* Method: addCategory
* Attach a category or tag to this article
*
* Parameters:
* categoryId - a string signifying a category ID
*
* Tags this article with _categoryID_.
* Does nothing if this article is already tagged with that ID.
*/
addCategory: function (categoryId) {
if (!this.hasCategory(categoryId))
this._categoryList.push(categoryId);
},
/**
* Method: getCategories
* List of this article's categories or tags
*
* Returns:
* An array of strings signifying category IDs.
*/
getCategories: function () {
return this._categoryList;
},
/**
* Method: hasCategory
* Whether this article is tagged with a particular ID
*
* Parameters:
* categoryId - a string signifying a category ID
*
* Returns:
* true if this article is tagged with _categoryId_, false if not.
*/
hasCategory: function (categoryId) {
return this._categoryList.indexOf(categoryId) != -1;
}
});
/**
* Function: newFromJson
* Construct a new <ArticleModel> from data exported by the CMS
*
* Parameters:
* json - a category object created by parsing the JSON file
*
* Returns:
* A newly created <ArticleModel>.
*
* See <DomainWikiModel.loadFromJson> for the structure of the JSON object.
*/
function newFromJson(json) {
let retval = new ArticleModel({
title: json['title'],
source: json['source'],
uri: json['url']
});
retval.setCategories(json['categories']);
return retval;
}
|