From a1b33089877660ba33331d76281e68790f35ae44 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 15 Dec 2017 06:52:54 +0100 Subject: keywords list --- public/assets/js/lib/views/details/details.js | 60 +++++++++++++++++++++ public/assets/js/lib/views/details/index.js | 60 --------------------- public/assets/js/lib/views/keywords/keywords.js | 72 +++++++++++++++++++++++++ 3 files changed, 132 insertions(+), 60 deletions(-) create mode 100644 public/assets/js/lib/views/details/details.js delete mode 100644 public/assets/js/lib/views/details/index.js create mode 100644 public/assets/js/lib/views/keywords/keywords.js (limited to 'public/assets/js/lib/views') diff --git a/public/assets/js/lib/views/details/details.js b/public/assets/js/lib/views/details/details.js new file mode 100644 index 0000000..1b67b92 --- /dev/null +++ b/public/assets/js/lib/views/details/details.js @@ -0,0 +1,60 @@ +var DetailsView = View.extend({ + + events: { + }, + + action: "/api/thread/", + keywordAction: "/api/keyword/", + + initialize: function(opt){ + this.comments = new CommentsView ({ parent: this }) + this.files = new FilesView ({ parent: this }) + this.gallery = new GalleryView ({ parent: this }) + this.form = new CommentForm ({ parent: this }) + this.threadbox = new ThreadBox ({ parent: this }) + this.settings = new ThreadSettingsForm ({ parent: this }) + $(".settings_link").click(this.openSettings.bind(this)) + }, + + load: function(id){ + id = id.replace(/\D/g, "") + $.ajax({ + method: "get", + url: this.action + id, + success: this.populate.bind(this), + error: app.router.error404, + }) + }, + + populate: function(data){ + this.data = data + // console.log(data) + set_background_color(data.thread.color || (data.keyword ? data.keyword.color : 'plain')) + $("body").removeClass('loading') + var thread = data.thread + $("h1").html(sanitize(thread.title)) + $("title").html(sanitize(thread.title)) + $(".metadata").html(metadata(thread)) + $(".settings_link").attr("href", "/details/" + thread.id + "/settings") + this.form.load(data.thread) + this.comments.load(data.comments, data.thread) + this.files.load(data.files, data.thread) + this.gallery.load(data.files, data.thread) + if (data.thread.keyword) { + $.get(this.keywordAction + data.thread.keyword, this.populateKeyword.bind(this)) + } + if (this.options.settings) { + this.openSettings() + } + }, + + populateKeyword: function(data){ + this.threadbox.load(data) + }, + + openSettings: function(e){ + e && e.preventDefault() + this.settings.show() + }, + +}) diff --git a/public/assets/js/lib/views/details/index.js b/public/assets/js/lib/views/details/index.js deleted file mode 100644 index 1b67b92..0000000 --- a/public/assets/js/lib/views/details/index.js +++ /dev/null @@ -1,60 +0,0 @@ -var DetailsView = View.extend({ - - events: { - }, - - action: "/api/thread/", - keywordAction: "/api/keyword/", - - initialize: function(opt){ - this.comments = new CommentsView ({ parent: this }) - this.files = new FilesView ({ parent: this }) - this.gallery = new GalleryView ({ parent: this }) - this.form = new CommentForm ({ parent: this }) - this.threadbox = new ThreadBox ({ parent: this }) - this.settings = new ThreadSettingsForm ({ parent: this }) - $(".settings_link").click(this.openSettings.bind(this)) - }, - - load: function(id){ - id = id.replace(/\D/g, "") - $.ajax({ - method: "get", - url: this.action + id, - success: this.populate.bind(this), - error: app.router.error404, - }) - }, - - populate: function(data){ - this.data = data - // console.log(data) - set_background_color(data.thread.color || (data.keyword ? data.keyword.color : 'plain')) - $("body").removeClass('loading') - var thread = data.thread - $("h1").html(sanitize(thread.title)) - $("title").html(sanitize(thread.title)) - $(".metadata").html(metadata(thread)) - $(".settings_link").attr("href", "/details/" + thread.id + "/settings") - this.form.load(data.thread) - this.comments.load(data.comments, data.thread) - this.files.load(data.files, data.thread) - this.gallery.load(data.files, data.thread) - if (data.thread.keyword) { - $.get(this.keywordAction + data.thread.keyword, this.populateKeyword.bind(this)) - } - if (this.options.settings) { - this.openSettings() - } - }, - - populateKeyword: function(data){ - this.threadbox.load(data) - }, - - openSettings: function(e){ - e && e.preventDefault() - this.settings.show() - }, - -}) diff --git a/public/assets/js/lib/views/keywords/keywords.js b/public/assets/js/lib/views/keywords/keywords.js new file mode 100644 index 0000000..acb76f1 --- /dev/null +++ b/public/assets/js/lib/views/keywords/keywords.js @@ -0,0 +1,72 @@ +var KeywordsView = View.extend({ + + el: "#keyword_list", + + events: { + }, + + action: "/api/keywords/statistics", + + initialize: function(opt){ + this.template = this.$(".template").html() + console.log(this.$(".template")) + }, + + load: function(){ + $.get(this.action, this.populate.bind(this)) + }, + + populate: function(data){ + console.log(data) + var keywordThreads = {} + data.threadGroups.forEach(kw => { + keywordThreads[kw.keyword] = kw + }) + data.keywords + .map(a => [parseInt((keywordThreads[a.keyword] || {})['sum(`viewed`)']) || 0, a]) + .sort((b,a) => cmp(a[0], b[0])) + .map(a => a[1]) + .forEach(keyword => { + var thread = keywordThreads[keyword.keyword.toLowerCase()] || { + title: '', + } + // { + // keyword: "warez", + // sum(`viewed`): "498", + // id: 701, + // title: "EMS SYNTHI PLUG FOR MAC", + // lastmodified: 1192401724 + // }, + console.log(keyword, thread) + var viewed = thread['sum(`viewed`)'] + var views = viewed ? hush_views(viewed) : ['',''] + var dot = privacy_dot(thread.privacy) + var datetime = verbose_date(keyword.createdate) + var age = get_age(thread.lastmodified) + var id = thread.id + get_revision(thread) + var t = this.template + .replace(/{{keyword}}/g, sanitize(keyword.keyword)) + .replace(/{{id}}/g, id) + .replace(/{{username}}/g, keyword.username) + .replace(/{{privacy_dot}}/g, dot) + .replace(/{{title}}/g, thread.title) + .replace(/{{date}}/g, datetime[0]) + .replace(/{{time}}/g, datetime[1]) + .replace(/{{date_class}}/g, carbon_date(thread.lastmodified) ) + .replace(/{{views}}/g, views[1]) +// .replace(/{{comments}}/g, comments[1]) +// .replace(/{{files}}/g, files[1]) +// .replace(/{{size}}/g, size[1] ) + .replace(/{{views_class}}/g, views[0]) +// .replace(/{{comments_class}}/g, comments[0]) +// .replace(/{{files_class}}/g, files[0]) +// .replace(/{{show_files}}/g, thread.file_count == 0 ? "hidden" : "") +// .replace(/{{size_class}}/g, size[0] ) + .replace(/{{color}}/g, thread.color || "blue" ) + + this.$el.append(t) + }) + $("body").removeClass('loading') + }, + +}) \ No newline at end of file -- cgit v1.2.3-70-g09d2