Merge lp:~jderose/dmedia/history into lp:dmedia

Proposed by Jason Gerard DeRose
Status: Merged
Merged at revision: 501
Proposed branch: lp:~jderose/dmedia/history
Merge into: lp:dmedia
Diff against target: 234 lines (+134/-9)
6 files modified
dmedia/importer.py (+3/-0)
dmedia/views.py (+26/-1)
ui/dmedia.js (+78/-1)
ui/grid.css (+0/-1)
ui/index.html (+4/-6)
ui/style.css (+23/-0)
To merge this branch: bzr merge lp:~jderose/dmedia/history
Reviewer Review Type Date Requested Status
James Raymond Approve
Review via email: mp+130923@code.launchpad.net

Description of the change

* Adds new project/history view to show completed dmedia/import docs, and a similar project/history filter function

* ImporterWorker now saves the thumbnail the dmedia/import doc for handy use by the History tab

* Added proof-of-concept History tab that shows the most recent 8 imports (card insert events), and responds to the changes feed

To post a comment you must log in.
Revision history for this message
James Raymond (jamesmr) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'dmedia/importer.py'
2--- dmedia/importer.py 2012-08-06 11:00:34 +0000
3+++ dmedia/importer.py 2012-10-23 01:39:21 +0000
4@@ -273,6 +273,9 @@
5 log.info('adding to %r', self.project)
6 self.project.save(doc)
7 if need_thumbnail and 'thumbnail' in doc['_attachments']:
8+ self.doc['_attachments'] = {}
9+ self.doc['_attachments']['thumbnail'] = doc['_attachments']['thumbnail']
10+ self.db.save(self.doc)
11 self.emit('import_thumbnail', self.id, ch.id)
12 need_thumbnail = False
13
14
15=== modified file 'dmedia/views.py'
16--- dmedia/views.py 2012-10-20 05:06:23 +0000
17+++ dmedia/views.py 2012-10-23 01:39:21 +0000
18@@ -286,19 +286,44 @@
19 }
20 """
21
22+project_history = """
23+function(doc) {
24+ if (doc.type == 'dmedia/import' && doc.time_end) {
25+ var value = {
26+ 'label': doc.partition.label,
27+ 'size': doc.partition.size,
28+ 'bytes': doc.stats.total.bytes,
29+ 'count': doc.stats.total.count,
30+ 'rate': doc.rate,
31+ }
32+ emit(doc.time, value);
33+ }
34+}
35+"""
36+
37+filter_project_history = """
38+function(doc, req) {
39+ if (doc.type == 'dmedia/import' && doc.time_end) {
40+ return true;
41+ }
42+ return false;
43+}
44+"""
45+
46 project_design = {
47 '_id': '_design/project',
48 'views': {
49 'atime': {'map': project_atime},
50 'title': {'map': project_title},
51+ 'history': {'map': project_history},
52 },
53 'filters': {
54 'type': filter_project_type,
55+ 'history': filter_project_history,
56 },
57 }
58
59
60-
61 # For dmedia/tag docs:
62 tag_key = """
63 function(doc) {
64
65=== modified file 'ui/dmedia.js'
66--- ui/dmedia.js 2012-10-20 23:11:23 +0000
67+++ ui/dmedia.js 2012-10-23 01:39:21 +0000
68@@ -42,7 +42,8 @@
69 },
70
71 init_history: function() {
72- console.log('init_history');
73+ UI.history = new History(db);
74+ UI.history.start();
75 },
76
77 init_browser: function() {
78@@ -339,6 +340,82 @@
79 },
80 }
81
82+
83+var History = function(db) {
84+ this.db = db;
85+ this.div = $('imports');
86+}
87+History.prototype = {
88+ start: function() {
89+ var self = this;
90+ var on_result = function(req) {
91+ self.on_result(req);
92+ }
93+ var options = {
94+ 'update_seq': true,
95+ 'descending': true,
96+ 'limit': 8,
97+ }
98+ this.db.view(on_result, 'project', 'history', options);
99+ },
100+
101+ on_result: function(req) {
102+ this.div.innerHTML = null;
103+ var result = req.read();
104+ result.rows.forEach(function(row) {
105+ var element = this.build(row);
106+ this.div.appendChild(element);
107+ }, this);
108+ this.monitor(result.update_seq);
109+ },
110+
111+ monitor: function(since) {
112+ this.since = since;
113+ var self = this;
114+ var callback = function(req) {
115+ self.on_changes(req);
116+ }
117+ var options = {
118+ 'since': since,
119+ 'feed': 'longpoll',
120+ 'filter': 'project/history',
121+ }
122+ this.db.get(callback, '_changes', options);
123+ },
124+
125+ on_changes: function(req) {
126+ var result = req.read();
127+ if (result.results.length > 0) {
128+ this.start();
129+ }
130+ else {
131+ this.monitor(result.last_seq);
132+ }
133+ },
134+
135+ build: function(row) {
136+ var value = row.value;
137+ var div = $el('div', {'class': 'thumbnail'});
138+ div.style.backgroundImage = this.db.att_css_url(row.id);
139+ var inner = div.appendChild($el('div'));
140+ var label = [value.size, value.label].join(', ');
141+ inner.appendChild(
142+ $el('p', {'textContent': format_date(row.key)})
143+ );
144+ inner.appendChild(
145+ $el('p', {'textContent': label})
146+ );
147+ inner.appendChild(
148+ $el('p', {'textContent': count_n_size(value.count, value.bytes)})
149+ );
150+ inner.appendChild(
151+ $el('p', {'textContent': value.rate})
152+ );
153+ return div;
154+ },
155+}
156+
157+
158 function Browser(project, player, items) {
159 this.player = $(player);
160 this.tags = $('tags');
161
162=== modified file 'ui/grid.css'
163--- ui/grid.css 2012-03-27 13:18:47 +0000
164+++ ui/grid.css 2012-10-23 01:39:21 +0000
165@@ -1,5 +1,4 @@
166 .grid_row {
167- white-space: nowrap;
168 font-size: 0;
169 line-height: 0;
170 }
171
172=== modified file 'ui/index.html'
173--- ui/index.html 2012-10-21 22:58:12 +0000
174+++ ui/index.html 2012-10-23 01:39:21 +0000
175@@ -25,7 +25,7 @@
176 </div>
177 </div>
178 <div class="content">
179- <div id="import_target" class="">
180+ <div id="import_target" class="hide">
181 <div id="choose_project" class="">
182 <form id="project_form"></form>
183 <div class="grid_row darkbar">
184@@ -57,13 +57,11 @@
185 <div id="cards" class="grid_row"></div>
186 </div>
187 </div>
188+
189 <div id="history_target" class="hide">
190- <div class="grid_row darkbar">
191- <div class="grid_1">History</div>
192- <input class="grid_3" placeholder="Date Search"></input>
193- <button class="grid_2">Search History</button>
194- </div>
195+ <div id="imports" class="grid_row"></div>
196 </div>
197+
198 <div id="browser_target" class="hide">
199 <div class="grid_row darkbar">
200 <select id="browser_projects" class="grid_1"></select>
201
202=== modified file 'ui/style.css'
203--- ui/style.css 2012-10-20 21:18:08 +0000
204+++ ui/style.css 2012-10-23 01:39:21 +0000
205@@ -218,6 +218,29 @@
206 text-shadow: 0 0 1px black;
207 }
208
209+#imports .thumbnail {
210+ height: 224px;
211+ width: 224px;
212+ box-shadow: 1px 2px 6px rgba(0, 0, 0, 0.6);
213+ background-color: #ddd;
214+ background-size: cover;
215+ background-position: center center;
216+ overflow: hidden;
217+ position: relative;
218+}
219+
220+#imports .thumbnail div {
221+ background-color: rgba(0, 0, 0, 0.35);
222+ padding: 5px;
223+ position: absolute;
224+ bottom: 0;
225+ width: 100%;
226+ overflow: hidden;
227+ font-size: 14px;
228+ color: white;
229+ text-shadow: 0 0 1px black;
230+}
231+
232
233 #tray {
234 position: fixed;

Subscribers

People subscribed via source and target branches