Skip to content

Commit 99df7fe

Browse files
committed
rename "collection" to "schema"
The idea here is that "schema" is easier to say, but also in the future where we put "schema" can be either the _name_ of a schema or an actual schema (useful for Form plugins and Controllers). This commit leaves all the tests largely as they were, triggering all the deprecation warnings as a test. The next commit will remove all the deprecation triggers in the tests, as well as make the deprecation warnings slightly less annoying... Refs #25
1 parent b02bd5b commit 99df7fe

35 files changed

+704
-625
lines changed

lib/Mojolicious/Plugin/Yancy.pm

+131-125
Large diffs are not rendered by default.

lib/Mojolicious/Plugin/Yancy/resources/public/yancy/app.js

+55-58
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,9 @@ var app = new Vue({
225225
data: function () {
226226
var current = this.parseHash();
227227
return {
228-
hasCollections: null,
229-
currentCollection: current.collection || null,
230-
collections: {},
228+
hasSchema: null,
229+
currentSchemaName: current.schema || null,
230+
schema: {},
231231
openedRow: null,
232232
deleteIndex: null,
233233
addingItem: false,
@@ -300,8 +300,8 @@ var app = new Vue({
300300
this.fetchPage();
301301
},
302302

303-
setCollection: function ( name ) {
304-
this.currentCollection = name;
303+
setSchema: function ( name ) {
304+
this.currentSchemaName = name;
305305
$( '#sidebar-collapse' ).collapse('hide');
306306
},
307307

@@ -316,9 +316,9 @@ var app = new Vue({
316316
},
317317

318318
parseSpec: function ( spec ) {
319-
var pathParts = [], collectionName, collection, pathObj, firstCollection;
320-
this.collections = {};
321-
this.hasCollections = false;
319+
var pathParts = [], schemaName, schema, pathObj, firstSchema;
320+
this.schema = {};
321+
this.hasSchema = false;
322322

323323
// Preprocess definitions
324324
for ( var defKey in spec.definitions ) {
@@ -372,74 +372,73 @@ var app = new Vue({
372372
pathObj = spec.paths[ pathKey ];
373373

374374
pathParts = pathKey.split( '/' );
375-
collectionName = pathParts[1];
375+
schemaName = pathParts[1];
376376

377-
// Skip hidden collections
378-
if ( spec.definitions[ collectionName ]['x-hidden'] ) {
377+
// Skip hidden schemas
378+
if ( spec.definitions[ schemaName ]['x-hidden'] ) {
379379
continue;
380380
}
381381

382-
collection = this.collections[ collectionName ];
383-
if ( !collection ) {
384-
collection = this.collections[ collectionName ] = {
382+
schema = this.schema[ schemaName ];
383+
if ( !schema ) {
384+
schema = this.schema[ schemaName ] = {
385385
operations: { }
386386
};
387387
}
388-
if ( !firstCollection ) {
389-
firstCollection = collectionName;
388+
if ( !firstSchema ) {
389+
firstSchema = schemaName;
390390
}
391-
this.hasCollections = true;
391+
this.hasSchema = true;
392392

393393
// Array operations
394394
if ( pathParts.length == 2 ) {
395395
if ( pathObj.get ) {
396-
collection.operations["list"] = {
396+
schema.operations["list"] = {
397397
url: [ spec.basePath, pathKey ].join(''),
398-
schema: spec.definitions[ collectionName ]
398+
schema: spec.definitions[ schemaName ]
399399
};
400400
}
401401
if ( pathObj.post ) {
402-
collection.operations["add"] = {
402+
schema.operations["add"] = {
403403
url: [ spec.basePath, pathKey ].join(''),
404-
schema: spec.definitions[ collectionName ]
404+
schema: spec.definitions[ schemaName ]
405405
};
406406
}
407407
}
408408
// Item operations
409409
else {
410410
if ( pathObj.get ) {
411-
collection.operations["get"] = {
411+
schema.operations["get"] = {
412412
url: [ spec.basePath, pathKey ].join(''),
413-
schema: spec.definitions[ collectionName ]
413+
schema: spec.definitions[ schemaName ]
414414
};
415415
}
416416
if ( pathObj.put ) {
417-
collection.operations["set"] = {
417+
schema.operations["set"] = {
418418
url: [ spec.basePath, pathKey ].join(''),
419-
schema: spec.definitions[ collectionName ]
419+
schema: spec.definitions[ schemaName ]
420420
};
421421
}
422422
if ( pathObj.delete ) {
423-
collection.operations["delete"] = {
423+
schema.operations["delete"] = {
424424
url: [ spec.basePath, pathKey ].join(''),
425-
schema: spec.definitions[ collectionName ]
425+
schema: spec.definitions[ schemaName ]
426426
};
427427
}
428428
}
429429
}
430430

431-
if ( this.currentCollection && this.collections[ this.currentCollection ] ) {
431+
if ( this.currentSchemaName && this.schema[ this.currentSchemaName ] ) {
432432
this.fetchPage();
433433
}
434434
else {
435-
this.currentCollection = firstCollection;
435+
this.currentSchemaName = firstSchema;
436436
}
437437
},
438438

439439
fetchPage: function () {
440440
if ( this.fetching ) return;
441-
var coll = this.collections[ this.currentCollection ],
442-
self = this,
441+
var self = this,
443442
query = {
444443
$limit: this.perPage,
445444
$offset: this.perPage * ( this.currentPage - 1 )
@@ -455,7 +454,7 @@ var app = new Vue({
455454

456455
this.fetching = true;
457456
delete this.error.fetchPage;
458-
$.get( coll.operations["list"].url, query ).done(
457+
$.get( this.currentOperations["list"].url, query ).done(
459458
function ( data, status, jqXHR ) {
460459
if ( query.offset > data.total ) {
461460
// We somehow got to a page that doesn't exist,
@@ -468,7 +467,7 @@ var app = new Vue({
468467

469468
self.items = data.items;
470469
self.total = data.total;
471-
self.columns = self.getListColumns( self.currentCollection ),
470+
self.columns = self.getListColumns( self.currentSchemaName ),
472471
self.fetching = false;
473472
self.updateHash();
474473
}
@@ -479,9 +478,8 @@ var app = new Vue({
479478
);
480479
},
481480

482-
getListColumns: function ( collName ) {
483-
var coll = this.collections[ collName ],
484-
schema = coll.operations["list"].schema,
481+
getListColumns: function ( schemaName ) {
482+
var schema = this.schema[ schemaName ].operations["list"].schema,
485483
props = schema.properties,
486484
columns = schema['x-list-columns'] || [];
487485
return columns.map( function (c) {
@@ -494,23 +492,22 @@ var app = new Vue({
494492

495493
parseHash: function () {
496494
var parts = location.hash.split( '/' ),
497-
collection = parts[1],
495+
schema = parts[1],
498496
page = parts[2];
499497
return {
500-
collection: collection,
498+
schema: schema,
501499
page: page
502500
};
503501
},
504502

505503
updateHash: function () {
506-
location.hash = "/" + this.currentCollection + "/" + this.currentPage;
504+
location.hash = "/" + this.currentSchemaName + "/" + this.currentPage;
507505
},
508506

509507
saveItem: function (i) {
510508
var self = this,
511-
coll = this.collections[ this.currentCollection ],
512-
value = this.prepareSaveItem( this.items[i], coll.operations['set'].schema ),
513-
url = this.fillUrl( coll.operations['set'].url, this.openedOldValue );
509+
value = this.prepareSaveItem( this.items[i], this.currentOperations['set'].schema ),
510+
url = this.fillUrl( this.currentOperations['set'].url, this.openedOldValue );
514511
delete this.error.saveItem;
515512
this.$set( this, 'formError', {} );
516513
$.ajax(
@@ -541,9 +538,9 @@ var app = new Vue({
541538

542539
addItem: function () {
543540
var self = this,
544-
coll = this.collections[ this.currentCollection ],
545-
value = this.prepareSaveItem( this.newItem, coll.operations['add'].schema ),
546-
url = coll.operations['add'].url;
541+
schema = this.currentSchema,
542+
value = this.prepareSaveItem( this.newItem, schema ),
543+
url = this.currentOperations['add'].url;
547544
delete this.error.addItem;
548545
this.$set( this, 'formError', {} );
549546
$.ajax(
@@ -555,13 +552,13 @@ var app = new Vue({
555552
}
556553
).done(
557554
function ( data, status, jqXHR ) {
558-
var id = coll.operations['add'].schema['x-id-field'] || 'id';
555+
var id = self.currentOperations['add'].schema['x-id-field'] || 'id';
559556
var urlParams = {};
560557
urlParams[ id ] = data;
561558

562559
$.ajax(
563560
{
564-
url: self.fillUrl( coll.operations['get'].url, urlParams ),
561+
url: self.fillUrl( self.currentOperations['get'].url, urlParams ),
565562
method: 'GET',
566563
dataType: 'json'
567564
}
@@ -654,7 +651,7 @@ var app = new Vue({
654651
},
655652

656653
createBlankItem: function () {
657-
var schema = this.collections[ this.currentCollection ].operations['add'].schema,
654+
var schema = this.currentSchema,
658655
item = {};
659656
if ( schema.example ) {
660657
return schema.example;
@@ -678,9 +675,9 @@ var app = new Vue({
678675
deleteItem: function () {
679676
var i = this.deleteIndex,
680677
self = this,
681-
coll = this.collections[ this.currentCollection ],
678+
schema = this.currentSchema,
682679
value = $( '#data-' + i ).val(),
683-
url = this.fillUrl( coll.operations['delete'].url, this.items[i] );
680+
url = this.fillUrl( this.currentOperations['delete'].url, this.items[i] );
684681
$.ajax(
685682
{
686683
url: url,
@@ -712,8 +709,8 @@ var app = new Vue({
712709
},
713710

714711
renderValue: function ( field, value ) {
715-
var coll = this.schema;
716-
var fieldType = coll.properties[ field ].type;
712+
var schema = this.currentSchema;
713+
var fieldType = schema.properties[ field ].type;
717714
var type = Array.isArray( fieldType ) ? fieldType[0] : fieldType;
718715
if ( type == 'boolean' ) {
719716
return value ? 'Yes' : 'No';
@@ -722,7 +719,7 @@ var app = new Vue({
722719
},
723720

724721
rowViewUrl: function ( data ) {
725-
return this.fillUrl( this.schema[ 'x-view-item-url' ], data );
722+
return this.fillUrl( this.currentSchema[ 'x-view-item-url' ], data );
726723
},
727724

728725
addToast: function ( toast ) {
@@ -766,15 +763,15 @@ var app = new Vue({
766763
return pages;
767764
},
768765

769-
operations: function () {
770-
return this.collections[ this.currentCollection ] ? this.collections[ this.currentCollection ].operations : {};
766+
currentOperations: function () {
767+
return this.schema[ this.currentSchemaName ] ? this.schema[ this.currentSchemaName ].operations : {};
771768
},
772-
schema: function () {
773-
return this.operations.get ? this.operations.get.schema : {};
769+
currentSchema: function () {
770+
return this.currentOperations.get ? this.currentOperations.get.schema : {};
774771
}
775772
},
776773
watch: {
777-
currentCollection: function () {
774+
currentSchemaName: function () {
778775
this.data = [];
779776
this.currentPage = 1;
780777
this.openedRow = null;

lib/Mojolicious/Plugin/Yancy/resources/templates/yancy/auth/password/register.html.ep

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
</div>
4040
% }
4141
% else {
42-
%= app->yancy->form->field_for( $plugin->collection, $field )
42+
%= app->yancy->form->field_for( $plugin->schema, $field )
4343
% }
4444
% }
4545
<button class="btn btn-primary">Register</button>

0 commit comments

Comments
 (0)