Merge lp:~rharding/juju-gui/api0 into lp:juju-gui/experimental

Proposed by Richard Harding on 2013-03-20
Status: Work in progress
Proposed branch: lp:~rharding/juju-gui/api0
Merge into: lp:juju-gui/experimental
Diff against target: 402 lines (+264/-17) (has conflicts)
2 files modified
app/models/charm.js (+169/-13)
app/store/charm.js (+95/-4)
Text conflict in app/models/charm.js
To merge this branch: bzr merge lp:~rharding/juju-gui/api0
Reviewer Review Type Date Requested Status
Juju GUI Hackers 2013-03-20 Pending
Review via email: mp+154385@code.launchpad.net

Description of the change

TBD

To post a comment you must log in.

Unmerged revisions

416. By Richard Harding on 2013-03-05

Start to work on the api calls for the charmstore

415. By Richard Harding on 2013-03-04

Fix the broken stuff

414. By Richard Harding on 2013-03-04

Working on model code

413. By Richard Harding on 2013-03-04

start to work on model resolution

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'app/models/charm.js'
--- app/models/charm.js 2013-03-11 13:51:08 +0000
+++ app/models/charm.js 2013-03-20 14:43:53 +0000
@@ -1,3 +1,4 @@
1/*global YUI:false*/
1'use strict';2'use strict';
23
3/**4/**
@@ -10,6 +11,7 @@
10YUI.add('juju-charm-models', function(Y) {11YUI.add('juju-charm-models', function(Y) {
1112
12 var models = Y.namespace('juju.models');13 var models = Y.namespace('juju.models');
14 // Check on the idea of the id.
13 var charmIdRe = /^(?:(\w+):)?(?:~(\S+)\/)?(\w+)\/(\S+?)-(\d+)$/;15 var charmIdRe = /^(?:(\w+):)?(?:~(\S+)\/)?(\w+)\/(\S+?)-(\d+)$/;
14 var idElements = ['scheme', 'owner', 'series', 'package_name', 'revision'];16 var idElements = ['scheme', 'owner', 'series', 'package_name', 'revision'];
15 var simpleCharmIdRe = /^(?:(\w+):)?(?!:~)(\w+)$/;17 var simpleCharmIdRe = /^(?:(\w+):)?(?!:~)(\w+)$/;
@@ -80,13 +82,20 @@
8082
81 initializer: function() {83 initializer: function() {
82 var id = this.get('id'),84 var id = this.get('id'),
85<<<<<<< TREE
83 parts = parseCharmId(id),86 parts = parseCharmId(id),
84 self = this;87 self = this;
85 if (!parts) {88 if (!parts) {
89=======
90 parts = id && charmIdRe.exec(id),
91 self = this;
92 if (!Y.Lang.isValue(id) || !parts) {
93>>>>>>> MERGE-SOURCE
86 throw 'Developers must initialize charms with a well-formed id.';94 throw 'Developers must initialize charms with a well-formed id.';
87 }95 }
88 this.loaded = false;96 this.loaded = false;
89 this.on('load', function() { this.loaded = true; });97 this.on('load', function() { this.loaded = true; });
98<<<<<<< TREE
90 Y.Object.each(99 Y.Object.each(
91 parts,100 parts,
92 function(value, key) { self.set(key, value); });101 function(value, key) { self.set(key, value); });
@@ -97,6 +106,16 @@
97 tmp.unshift('~' + owner);106 tmp.unshift('~' + owner);
98 }107 }
99 this.set('full_name', tmp.join('/'));108 this.set('full_name', tmp.join('/'));
109=======
110 parts.shift();
111 var attrs = Y.Array.zip(idElements, parts);
112 Y.each(
113 attrs,
114 function(pair) {
115 self.set(pair[0], pair[1]);
116 }
117 );
118>>>>>>> MERGE-SOURCE
100 },119 },
101120
102 sync: function(action, options, callback) {121 sync: function(action, options, callback) {
@@ -120,25 +139,25 @@
120 }139 }
121 }140 }
122 );141 );
123 } else if (Y.Lang.isValue(options.loadByPath)) {142 } else if (Y.Lang.isValue(options.charm)) {
124 // This is a charm store.143 // This is a charm store.
125 options.loadByPath(144 options.charm(
126 this.get('charm_store_path'),145 this.get('charm_store_path'), {
127 { success: function(response) {146 success: function(response) {
128 callback(false, response);147 callback(false, response);
129 },148 },
130 failure: function(response) {149 failure: function(response) {
131 callback(true, response);150 callback(true, response);
132 }151 }
133 });152 });
134 } else {153 } else {
135 throw 'You must supply a get_charm or loadByPath function.';154 throw 'You must supply a CharmStore.charm or loadByPath function.';
136 }155 }
137 },156 },
138157
139 parse: function() {158 parse: function() {
140 var data = Charm.superclass.parse.apply(this, arguments),159 var data = Charm.superclass.parse.apply(this, arguments),
141 self = this;160 self = this;
142 data.is_subordinate = data.subordinate;161 data.is_subordinate = data.subordinate;
143 Y.each(data, function(value, key) {162 Y.each(data, function(value, key) {
144 if (!value ||163 if (!value ||
@@ -157,7 +176,7 @@
157 // Official charms sort before owned charms.176 // Official charms sort before owned charms.
158 // If !X.owner, that means it is owned by charmers.177 // If !X.owner, that means it is owned by charmers.
159 var owner = this.get('owner'),178 var owner = this.get('owner'),
160 otherOwner = other.get('owner');179 otherOwner = other.get('owner');
161 if (!owner && otherOwner) {180 if (!owner && otherOwner) {
162 return -1;181 return -1;
163 } else if (owner && !otherOwner) {182 } else if (owner && !otherOwner) {
@@ -183,11 +202,33 @@
183 return Y.Lang.isString(val) && !!charmIdRe.exec(val);202 return Y.Lang.isString(val) && !!charmIdRe.exec(val);
184 }203 }
185 },204 },
186 bzr_branch: {writeOnce: true},205 charm_store_path: {
187 charm_store_path: {writeOnce: true},206 getter: function () {
207 // charm_store_path
208 var owner = this.get('owner');
209 return [
210 (owner ? '~' + owner : 'charms'),
211 this.get('series'),
212 (this.get('package_name') + '-' + this.get('revision')),
213 'json'
214 ].join('/');
215 },
216 writeOnce: true
217 },
188 config: {writeOnce: true},218 config: {writeOnce: true},
189 description: {writeOnce: true},219 description: {writeOnce: true},
190 full_name: {writeOnce: true},220 full_name: {
221 getter: function () {
222 // full_name
223 var tmp = [this.get('series'), this.get('package_name')],
224 owner = this.get('owner');
225 if (owner) {
226 tmp.unshift('~' + owner);
227 }
228 return tmp.join('/');
229 },
230 writeOnce: true
231 },
191 is_subordinate: {writeOnce: true},232 is_subordinate: {writeOnce: true},
192 last_change: {233 last_change: {
193 writeOnce: true,234 writeOnce: true,
@@ -207,9 +248,9 @@
207 }248 }
208 },249 },
209 maintainer: {writeOnce: true},250 maintainer: {writeOnce: true},
210 metadata: {writeOnce: true},251 //metadata: {writeOnce: true},
252 owner: {writeOnce: true},
211 package_name: {writeOnce: true},253 package_name: {writeOnce: true},
212 owner: {writeOnce: true},
213 peers: {writeOnce: true},254 peers: {writeOnce: true},
214 proof: {writeOnce: true},255 proof: {writeOnce: true},
215 provides: {writeOnce: true},256 provides: {writeOnce: true},
@@ -272,6 +313,119 @@
272 });313 });
273 models.CharmList = CharmList;314 models.CharmList = CharmList;
274315
316
317 models.BrowserCharm = Y.Base.create('browser-charm', Charm, [], {
318
319 }, {
320 ATTRS: {
321 id: {
322 writeOnce: true,
323 validator: function(val) {
324 return Y.Lang.isString(val) && !!charmIdRe.exec(val);
325 }
326 },
327 bzr_branch: {writeOnce: true},
328 categories: {
329 value: [],
330 writeOnce: true
331 },
332 changelog: {
333 value: {},
334 writeOnce: true
335 },
336 charm_store_path: {writeOnce: true},
337 code_source: {writeOnce: true},
338 date_created: {writeOnce: true},
339 description: {writeOnce: true},
340 files: {
341 value: {},
342 writeOnce: true
343 },
344 full_name: {
345 getter: function () {
346 // full_name
347 var tmp = [this.get('series'), this.get('package_name')],
348 owner = this.get('owner');
349 if (owner) {
350 tmp.unshift('~' + owner);
351 }
352 return tmp.join('/');
353 },
354 writeOnce: true
355 },
356 is_approved: {writeOnce: true},
357 is_new: {writeOnce: true},
358 is_popular:{writeOnce: true},
359 is_subordinate: {writeOnce: true},
360 last_change: {
361 writeOnce: true,
362
363 /**
364 * Normalize created value from float to date object.
365 *
366 * @method last_change.writeOnce.setter
367 */
368 setter: function(val) {
369 if (val && val.created) {
370 // Mutating in place should be fine since this should only
371 // come from loading over the wire.
372 val.created = new Date(val.created * 1000);
373 }
374 return val;
375 }
376 },
377 maintainer: {writeOnce: true},
378 //metadata: {writeOnce: true},
379 name: {writeOnce: true},
380 config: {writeOnce: true},
381 owner: {writeOnce: true},
382 peers: {writeOnce: true},
383 proof: {writeOnce: true},
384 provides: {writeOnce: true},
385 rating_numerator: {writeOnce: true},
386 rating_denominator: {writeOnce: true},
387 recent_downloads: {writeOnce: true},
388 relations: {writeOnce: true},
389 requires: {writeOnce: true},
390 revision: {
391 writeOnce: true,
392
393 /**
394 * Parse the revision number out of a string.
395 *
396 * @method revision.writeOnce.setter
397 */
398 setter: function(val) {
399 if (Y.Lang.isValue(val)) {
400 val = parseInt(val, 10);
401 }
402 return val;
403 }
404 },
405 scheme: {
406 value: 'cs',
407 writeOnce: true,
408
409 /**
410 * If no value is given, "cs" is used as the default.
411 *
412 * @method scheme.writeOnce.setter
413 */
414 setter: function(val) {
415 if (!Y.Lang.isValue(val)) {
416 val = 'cs';
417 }
418 return val;
419 }
420 },
421 series: {writeOnce: true},
422 summary: {writeOnce: true},
423 tested_providers: {writeOnce: true},
424 url: {writeOnce: true}
425 }
426 });
427
428
275}, '0.1.0', {429}, '0.1.0', {
276 requires: [430 requires: [
277 'model',431 'model',
@@ -279,3 +433,5 @@
279 'juju-charm-id'433 'juju-charm-id'
280 ]434 ]
281});435});
436
437// vim: set tabstop=2:shiftwidth=2
282438
=== modified file 'app/store/charm.js'
--- app/store/charm.js 2013-03-11 13:56:47 +0000
+++ app/store/charm.js 2013-03-20 14:43:53 +0000
@@ -1,3 +1,4 @@
1/*global YUI: false, escape: false*/
1'use strict';2'use strict';
23
3/**4/**
@@ -9,14 +10,18 @@
910
10YUI.add('juju-charm-store', function(Y) {11YUI.add('juju-charm-store', function(Y) {
1112
13 var ns = Y.namespace('juju');
14
12 /**15 /**
13 * The CharmStore class.16 * The CharmStore class.
14 *17 *
15 * @class CharmStore18 * @class CharmStore
19 * @extends {Y.Base}
20 *
16 */21 */
17 var CharmStore = Y.Base.create('charm', Y.Base, [], {22 var CharmStore = Y.Base.create('charm', Y.Base, [], {
1823
19 loadByPath: function(path, options) {24 charm: function(path, options) {
20 this.get('datasource').sendRequest({25 this.get('datasource').sendRequest({
21 request: path,26 request: path,
22 callback: {27 callback: {
@@ -131,12 +136,98 @@
131 }136 }
132 }137 }
133 });138 });
134 Y.namespace('juju').CharmStore = CharmStore;139 ns.CharmStore = CharmStore;
135140
136}, '0.1.0', {141
142 /**
143 * Provides hook up to the Charmworld Api v0
144 *
145 * @class Charmworld0
146 * @extends {Y.Base}
147 *
148 */
149 ns.Charmworld0 = Y.Base.create('browser-api-0', Y.Base, [], {
150 _api_path: 'api/0/',
151
152 _endpoints: {
153 'charm': 'charm/{id}/',
154 'find': 'charms/',
155 'qa': 'charm/{id}/qa/',
156 'file': 'charm/{id}/files/{path}/',
157 },
158
159 charm: function(charmid, options) {
160 var path = Y.sub(this._endpoints, {id: charmid});
161
162 // path is known
163 this.get('datasource').sendRequest({
164 request: path,
165 callback: {
166 success: function(io_request) {
167 debugger;
168 options.success(
169 Y.JSON.parse(io_request.response.results[0].responseText));
170 },
171 failure: options.failure
172 }
173 });
174 },
175
176 find: function() {
177
178 },
179
180 initializer: function(cfg) {
181
182 },
183
184 qa: function() {
185
186 },
187
188 file: function() {
189
190 }
191
192 }, {
193 ATTRS: {
194 /**
195 * api_host is the host to the api server used for all calls. It auto
196 * creates the datasource instance when set.
197 *
198 * @attribute api_host
199 * @default ''
200 * @type {String}
201 *
202 */
203 api_host: {
204 setter: function(val) {
205 var api_endpoint = [val, this._api_path].join('/');
206 this.set(
207 'datasource',
208 new Y.DataSource.IO({ source: api_endpoint }));
209 return val;
210 }
211 },
212
213 /**
214 * datasource is auto set as part of the api_host ATTR.
215 *
216 * @attribute datasource
217 * @default undefined
218 * @type {Y.DataSource.IO}
219 *
220 */
221 datasource: {}
222 }
223 });
224
225} , '0.1.0', {
137 requires: [226 requires: [
138 'juju-charm-id',227 'juju-charm-id',
139 'datasource-io',228 'datasource-io',
140 'json-parse'229 'json-parse'
141 ]230 ]
142});231});
232
233// vim: set tabstop=2:shiftwidth=2

Subscribers

People subscribed via source and target branches