@@ -225,9 +225,9 @@ var app = new Vue({
225
225
data : function ( ) {
226
226
var current = this . parseHash ( ) ;
227
227
return {
228
- hasCollections : null ,
229
- currentCollection : current . collection || null ,
230
- collections : { } ,
228
+ hasSchema : null ,
229
+ currentSchemaName : current . schema || null ,
230
+ schema : { } ,
231
231
openedRow : null ,
232
232
deleteIndex : null ,
233
233
addingItem : false ,
@@ -300,8 +300,8 @@ var app = new Vue({
300
300
this . fetchPage ( ) ;
301
301
} ,
302
302
303
- setCollection : function ( name ) {
304
- this . currentCollection = name ;
303
+ setSchema : function ( name ) {
304
+ this . currentSchemaName = name ;
305
305
$ ( '#sidebar-collapse' ) . collapse ( 'hide' ) ;
306
306
} ,
307
307
@@ -316,9 +316,9 @@ var app = new Vue({
316
316
} ,
317
317
318
318
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 ;
322
322
323
323
// Preprocess definitions
324
324
for ( var defKey in spec . definitions ) {
@@ -372,74 +372,73 @@ var app = new Vue({
372
372
pathObj = spec . paths [ pathKey ] ;
373
373
374
374
pathParts = pathKey . split ( '/' ) ;
375
- collectionName = pathParts [ 1 ] ;
375
+ schemaName = pathParts [ 1 ] ;
376
376
377
- // Skip hidden collections
378
- if ( spec . definitions [ collectionName ] [ 'x-hidden' ] ) {
377
+ // Skip hidden schemas
378
+ if ( spec . definitions [ schemaName ] [ 'x-hidden' ] ) {
379
379
continue ;
380
380
}
381
381
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 ] = {
385
385
operations : { }
386
386
} ;
387
387
}
388
- if ( ! firstCollection ) {
389
- firstCollection = collectionName ;
388
+ if ( ! firstSchema ) {
389
+ firstSchema = schemaName ;
390
390
}
391
- this . hasCollections = true ;
391
+ this . hasSchema = true ;
392
392
393
393
// Array operations
394
394
if ( pathParts . length == 2 ) {
395
395
if ( pathObj . get ) {
396
- collection . operations [ "list" ] = {
396
+ schema . operations [ "list" ] = {
397
397
url : [ spec . basePath , pathKey ] . join ( '' ) ,
398
- schema : spec . definitions [ collectionName ]
398
+ schema : spec . definitions [ schemaName ]
399
399
} ;
400
400
}
401
401
if ( pathObj . post ) {
402
- collection . operations [ "add" ] = {
402
+ schema . operations [ "add" ] = {
403
403
url : [ spec . basePath , pathKey ] . join ( '' ) ,
404
- schema : spec . definitions [ collectionName ]
404
+ schema : spec . definitions [ schemaName ]
405
405
} ;
406
406
}
407
407
}
408
408
// Item operations
409
409
else {
410
410
if ( pathObj . get ) {
411
- collection . operations [ "get" ] = {
411
+ schema . operations [ "get" ] = {
412
412
url : [ spec . basePath , pathKey ] . join ( '' ) ,
413
- schema : spec . definitions [ collectionName ]
413
+ schema : spec . definitions [ schemaName ]
414
414
} ;
415
415
}
416
416
if ( pathObj . put ) {
417
- collection . operations [ "set" ] = {
417
+ schema . operations [ "set" ] = {
418
418
url : [ spec . basePath , pathKey ] . join ( '' ) ,
419
- schema : spec . definitions [ collectionName ]
419
+ schema : spec . definitions [ schemaName ]
420
420
} ;
421
421
}
422
422
if ( pathObj . delete ) {
423
- collection . operations [ "delete" ] = {
423
+ schema . operations [ "delete" ] = {
424
424
url : [ spec . basePath , pathKey ] . join ( '' ) ,
425
- schema : spec . definitions [ collectionName ]
425
+ schema : spec . definitions [ schemaName ]
426
426
} ;
427
427
}
428
428
}
429
429
}
430
430
431
- if ( this . currentCollection && this . collections [ this . currentCollection ] ) {
431
+ if ( this . currentSchemaName && this . schema [ this . currentSchemaName ] ) {
432
432
this . fetchPage ( ) ;
433
433
}
434
434
else {
435
- this . currentCollection = firstCollection ;
435
+ this . currentSchemaName = firstSchema ;
436
436
}
437
437
} ,
438
438
439
439
fetchPage : function ( ) {
440
440
if ( this . fetching ) return ;
441
- var coll = this . collections [ this . currentCollection ] ,
442
- self = this ,
441
+ var self = this ,
443
442
query = {
444
443
$limit : this . perPage ,
445
444
$offset : this . perPage * ( this . currentPage - 1 )
@@ -455,7 +454,7 @@ var app = new Vue({
455
454
456
455
this . fetching = true ;
457
456
delete this . error . fetchPage ;
458
- $ . get ( coll . operations [ "list" ] . url , query ) . done (
457
+ $ . get ( this . currentOperations [ "list" ] . url , query ) . done (
459
458
function ( data , status , jqXHR ) {
460
459
if ( query . offset > data . total ) {
461
460
// We somehow got to a page that doesn't exist,
@@ -468,7 +467,7 @@ var app = new Vue({
468
467
469
468
self . items = data . items ;
470
469
self . total = data . total ;
471
- self . columns = self . getListColumns ( self . currentCollection ) ,
470
+ self . columns = self . getListColumns ( self . currentSchemaName ) ,
472
471
self . fetching = false ;
473
472
self . updateHash ( ) ;
474
473
}
@@ -479,9 +478,8 @@ var app = new Vue({
479
478
) ;
480
479
} ,
481
480
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 ,
485
483
props = schema . properties ,
486
484
columns = schema [ 'x-list-columns' ] || [ ] ;
487
485
return columns . map ( function ( c ) {
@@ -494,23 +492,22 @@ var app = new Vue({
494
492
495
493
parseHash : function ( ) {
496
494
var parts = location . hash . split ( '/' ) ,
497
- collection = parts [ 1 ] ,
495
+ schema = parts [ 1 ] ,
498
496
page = parts [ 2 ] ;
499
497
return {
500
- collection : collection ,
498
+ schema : schema ,
501
499
page : page
502
500
} ;
503
501
} ,
504
502
505
503
updateHash : function ( ) {
506
- location . hash = "/" + this . currentCollection + "/" + this . currentPage ;
504
+ location . hash = "/" + this . currentSchemaName + "/" + this . currentPage ;
507
505
} ,
508
506
509
507
saveItem : function ( i ) {
510
508
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 ) ;
514
511
delete this . error . saveItem ;
515
512
this . $set ( this , 'formError' , { } ) ;
516
513
$ . ajax (
@@ -541,9 +538,9 @@ var app = new Vue({
541
538
542
539
addItem : function ( ) {
543
540
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 ;
547
544
delete this . error . addItem ;
548
545
this . $set ( this , 'formError' , { } ) ;
549
546
$ . ajax (
@@ -555,13 +552,13 @@ var app = new Vue({
555
552
}
556
553
) . done (
557
554
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' ;
559
556
var urlParams = { } ;
560
557
urlParams [ id ] = data ;
561
558
562
559
$ . ajax (
563
560
{
564
- url : self . fillUrl ( coll . operations [ 'get' ] . url , urlParams ) ,
561
+ url : self . fillUrl ( self . currentOperations [ 'get' ] . url , urlParams ) ,
565
562
method : 'GET' ,
566
563
dataType : 'json'
567
564
}
@@ -654,7 +651,7 @@ var app = new Vue({
654
651
} ,
655
652
656
653
createBlankItem : function ( ) {
657
- var schema = this . collections [ this . currentCollection ] . operations [ 'add' ] . schema ,
654
+ var schema = this . currentSchema ,
658
655
item = { } ;
659
656
if ( schema . example ) {
660
657
return schema . example ;
@@ -678,9 +675,9 @@ var app = new Vue({
678
675
deleteItem : function ( ) {
679
676
var i = this . deleteIndex ,
680
677
self = this ,
681
- coll = this . collections [ this . currentCollection ] ,
678
+ schema = this . currentSchema ,
682
679
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 ] ) ;
684
681
$ . ajax (
685
682
{
686
683
url : url ,
@@ -712,8 +709,8 @@ var app = new Vue({
712
709
} ,
713
710
714
711
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 ;
717
714
var type = Array . isArray ( fieldType ) ? fieldType [ 0 ] : fieldType ;
718
715
if ( type == 'boolean' ) {
719
716
return value ? 'Yes' : 'No' ;
@@ -722,7 +719,7 @@ var app = new Vue({
722
719
} ,
723
720
724
721
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 ) ;
726
723
} ,
727
724
728
725
addToast : function ( toast ) {
@@ -766,15 +763,15 @@ var app = new Vue({
766
763
return pages ;
767
764
} ,
768
765
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 : { } ;
771
768
} ,
772
- schema : function ( ) {
773
- return this . operations . get ? this . operations . get . schema : { } ;
769
+ currentSchema : function ( ) {
770
+ return this . currentOperations . get ? this . currentOperations . get . schema : { } ;
774
771
}
775
772
} ,
776
773
watch : {
777
- currentCollection : function ( ) {
774
+ currentSchemaName : function ( ) {
778
775
this . data = [ ] ;
779
776
this . currentPage = 1 ;
780
777
this . openedRow = null ;
0 commit comments