summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Isaacs <nick@endlessm.com>2013-07-25 21:09:39 -0700
committerPhilip Chimento <philip.chimento@gmail.com>2013-07-26 18:17:37 -0700
commit6fca9c7919b7198c24ae8cc8e1afda10e499b279 (patch)
tree8eba475b19969df14ec1c8996a2d686dde39abec
parente0f36b294218a655f3617057386da30e90a78aad (diff)
Fixed the presenter to parse the JSON file itself.
-rw-r--r--wikipedia/src/endless_wikipedia/PrebuiltWikipediaApplication.js3
-rw-r--r--wikipedia/src/presenters/domain_wiki_presenter.js42
2 files changed, 43 insertions, 2 deletions
diff --git a/wikipedia/src/endless_wikipedia/PrebuiltWikipediaApplication.js b/wikipedia/src/endless_wikipedia/PrebuiltWikipediaApplication.js
index be0bdc5..3486919 100644
--- a/wikipedia/src/endless_wikipedia/PrebuiltWikipediaApplication.js
+++ b/wikipedia/src/endless_wikipedia/PrebuiltWikipediaApplication.js
@@ -23,7 +23,8 @@ const PrebuiltWikipediaApplication = new Lang.Class({
vfunc_startup: function() {
this.parent();
this._domain_wiki_view = new DomainWikiView.DomainWikiView(this);
- this._domain_wiki_presenter = new DomainWikiPresenter.DomainWikiPresenter(this._domain_wiki_model, this._domain_wiki_view);
+ let filename = this.application_uri;
+ this._domain_wiki_presenter = new DomainWikiPresenter.DomainWikiPresenter(this._domain_wiki_model, this._domain_wiki_view, filename);
this._domain_wiki_view.set_categories(categories);
diff --git a/wikipedia/src/presenters/domain_wiki_presenter.js b/wikipedia/src/presenters/domain_wiki_presenter.js
index 2ac07f3..50346b3 100644
--- a/wikipedia/src/presenters/domain_wiki_presenter.js
+++ b/wikipedia/src/presenters/domain_wiki_presenter.js
@@ -1,22 +1,62 @@
const Lang = imports.lang;
const GObject = imports.gi.GObject;
+//Local Libraries
+const Utils = imports.utils;
+
const DomainWikiPresenter = new Lang.Class({
Name: "DomainWikiPresenter",
Extends: GObject.Object,
- _init: function(model, view) {
+ _init: function(model, view, filename) {
this._domain_wiki_model = model;
this._domain_wiki_view = view;
this._domain_wiki_view.set_presenter(this)
this._domain_wiki_view.connect('category-chosen', Lang.bind(this, this._onCategoryClicked));
this._domain_wiki_view.connect('article-chosen', Lang.bind(this, this._onArticleClicked));
+ this.initFromJsonFile(filename);
+
let categories = this._domain_wiki_model.getCategories();
this._domain_wiki_view.set_categories(categories);
},
+
+ initArticleModels: function(articles) {
+ let _articles = new Array();
+ for(let i = 0; i < articles.length; i++) {
+ let humanTitle = articles[i].title;
+ let wikipediaURL = articles[i].url;
+ let newArticle = new ArticleModel.ArticleModel({ title: humanTitle, uri: wikipediaURL});
+ _articles.push(newArticle);
+ }
+ return _articles;
+ },
+
+ initFromJsonFile: function(filename) {
+ let app_content = JSON.parse(Utils.load_file (filename));
+ this._application_name = app_content['app_name'];
+ this._image_uri = app_content['image_uri'];
+ this._lang_code = filename.substring(0, 2);
+ let categories = app_content['categories'];
+ let cat_length = categories.length
+ categories = new Array();
+ for(let i = 0; i < cat_length; i++){
+ let category = categories[i];
+ let categoryModel = initCategory(category);
+ let articles = category['articles'];
+ categoryModel.addArticles(initArticleModels(articles));
+ categories.push(categoryModel);
+ }
+ this._domain_wiki_model.addCategories(categories);
+ },
+
+ initCategory: function(category){
+ let params = {description:category['content_text'], image_uri:category['image_uri'], title:category['category_name']};
+ return new CategoryModel.CategoryModel(params);
+ },
+
_onCategoryClicked: function(page, title, index) {
this._current_category = index;
let category = this._domain_wiki_model.getCategories()[index];