@ -32,9 +32,10 @@ export class SchemasState {
public schemasItems = new BehaviorSubject < ImmutableArray < SchemaDto > > ( ImmutableArray . empty ( ) ) ;
public schemasItems = new BehaviorSubject < ImmutableArray < SchemaDto > > ( ImmutableArray . empty ( ) ) ;
public selectedSchema = new BehaviorSubject < SchemaDetailsDto | null > ( null ) ;
public selectedSchema = new BehaviorSubject < SchemaDetailsDto | null > ( null ) ;
public selectedReferencedSchema = new BehaviorSubject < SchemaDetailsDto | null > ( null ) ;
private get app() {
private get appName () {
return this . appsState . selectedApp . value ! . n ame;
return this . appsState . appN ame;
}
}
private get user() {
private get user() {
@ -49,28 +50,35 @@ export class SchemasState {
) {
) {
}
}
public selectSchema ( id : string | null ) : Observable < boolean > {
public selectSchema ( id : string | null ) : Observable < SchemaDetailsDto | null > {
const observable =
return this . loadSchema ( id )
! id ?
. do ( schema = > {
this . selectedSchema . next ( schema ) ;
} ) ;
}
public selectReferencedSchema ( id : string | null ) : Observable < SchemaDetailsDto | null > {
return this . loadSchema ( id )
. do ( schema = > {
this . selectedReferencedSchema . next ( schema ) ;
} ) ;
}
private loadSchema ( id : string | null ) {
return ! id ?
Observable . of ( null ) :
Observable . of ( null ) :
Observable . of ( < SchemaDetailsDto > this . schemasItems . value . find ( x = > x . id === id && x instanceof SchemaDetailsDto ) )
Observable . of ( < SchemaDetailsDto > this . schemasItems . value . find ( x = > x . id === id && x instanceof SchemaDetailsDto ) )
. switchMap ( schema = > {
. switchMap ( schema = > {
if ( ! schema ) {
if ( ! schema ) {
return this . schemasService . getSchema ( this . app , id ) . catch ( ( ) = > Observable . of ( null ) ) ;
return this . schemasService . getSchema ( this . appName , id ) . catch ( ( ) = > Observable . of ( null ) ) ;
} else {
} else {
return Observable . of ( schema ) ;
return Observable . of ( schema ) ;
}
}
} ) ;
} ) ;
return observable
. do ( schema = > {
this . selectedSchema . next ( schema ) ;
} )
. map ( s = > s !== null ) ;
}
}
public load ( ) : Observable < any > {
public load ( ) : Observable < any > {
return this . schemasService . getSchemas ( this . app )
return this . schemasService . getSchemas ( this . appName )
. catch ( error = > this . dialogs . notifyError ( error ) )
. catch ( error = > this . dialogs . notifyError ( error ) )
. do ( dtos = > {
. do ( dtos = > {
this . schemasItems . nextBy ( v = > ImmutableArray . of ( dtos ) ) ;
this . schemasItems . nextBy ( v = > ImmutableArray . of ( dtos ) ) ;
@ -78,21 +86,21 @@ export class SchemasState {
}
}
public create ( request : CreateSchemaDto ) {
public create ( request : CreateSchemaDto ) {
return this . schemasService . postSchema ( this . app , request , this . user , DateTime . now ( ) )
return this . schemasService . postSchema ( this . appName , request , this . user , DateTime . now ( ) )
. do ( dto = > {
. do ( dto = > {
this . schemasItems . nextBy ( v = > v . push ( dto ) ) ;
this . schemasItems . nextBy ( v = > v . push ( dto ) ) ;
} ) ;
} ) ;
}
}
public addField ( schema : SchemaDetailsDto , request : AddFieldDto ) : Observable < FieldDto > {
public addField ( schema : SchemaDetailsDto , request : AddFieldDto ) : Observable < FieldDto > {
return this . schemasService . postField ( this . app , schema . name , request , schema . version )
return this . schemasService . postField ( this . appName , schema . name , request , schema . version )
. do ( dto = > {
. do ( dto = > {
this . replaceSchema ( schema . addField ( dto . payload , this . user , dto . version ) ) ;
this . replaceSchema ( schema . addField ( dto . payload , this . user , dto . version ) ) ;
} ) . map ( d = > d . payload ) ;
} ) . map ( d = > d . payload ) ;
}
}
public publish ( schema : SchemaDto ) : Observable < any > {
public publish ( schema : SchemaDto ) : Observable < any > {
return this . schemasService . publishSchema ( this . app , schema . name , schema . version )
return this . schemasService . publishSchema ( this . appName , schema . name , schema . version )
. catch ( error = > this . dialogs . notifyError ( error ) )
. catch ( error = > this . dialogs . notifyError ( error ) )
. do ( dto = > {
. do ( dto = > {
this . replaceSchema ( schema . publish ( this . user , dto . version ) ) ;
this . replaceSchema ( schema . publish ( this . user , dto . version ) ) ;
@ -100,7 +108,7 @@ export class SchemasState {
}
}
public unpublish ( schema : SchemaDto ) : Observable < any > {
public unpublish ( schema : SchemaDto ) : Observable < any > {
return this . schemasService . unpublishSchema ( this . app , schema . name , schema . version )
return this . schemasService . unpublishSchema ( this . appName , schema . name , schema . version )
. catch ( error = > this . dialogs . notifyError ( error ) )
. catch ( error = > this . dialogs . notifyError ( error ) )
. do ( dto = > {
. do ( dto = > {
this . replaceSchema ( schema . unpublish ( this . user , dto . version ) ) ;
this . replaceSchema ( schema . unpublish ( this . user , dto . version ) ) ;
@ -108,7 +116,7 @@ export class SchemasState {
}
}
public enableField ( schema : SchemaDetailsDto , field : FieldDto ) : Observable < any > {
public enableField ( schema : SchemaDetailsDto , field : FieldDto ) : Observable < any > {
return this . schemasService . enableField ( this . app , schema . name , field . fieldId , schema . version )
return this . schemasService . enableField ( this . appName , schema . name , field . fieldId , schema . version )
. catch ( error = > this . dialogs . notifyError ( error ) )
. catch ( error = > this . dialogs . notifyError ( error ) )
. do ( dto = > {
. do ( dto = > {
this . replaceSchema ( schema . updateField ( field . enable ( ) , this . user , dto . version ) ) ;
this . replaceSchema ( schema . updateField ( field . enable ( ) , this . user , dto . version ) ) ;
@ -116,7 +124,7 @@ export class SchemasState {
}
}
public disableField ( schema : SchemaDetailsDto , field : FieldDto ) : Observable < any > {
public disableField ( schema : SchemaDetailsDto , field : FieldDto ) : Observable < any > {
return this . schemasService . disableField ( this . app , schema . name , field . fieldId , schema . version )
return this . schemasService . disableField ( this . appName , schema . name , field . fieldId , schema . version )
. catch ( error = > this . dialogs . notifyError ( error ) )
. catch ( error = > this . dialogs . notifyError ( error ) )
. do ( dto = > {
. do ( dto = > {
this . replaceSchema ( schema . updateField ( field . disable ( ) , this . user , dto . version ) ) ;
this . replaceSchema ( schema . updateField ( field . disable ( ) , this . user , dto . version ) ) ;
@ -124,7 +132,7 @@ export class SchemasState {
}
}
public lockField ( schema : SchemaDetailsDto , field : FieldDto ) : Observable < any > {
public lockField ( schema : SchemaDetailsDto , field : FieldDto ) : Observable < any > {
return this . schemasService . lockField ( this . app , schema . name , field . fieldId , schema . version )
return this . schemasService . lockField ( this . appName , schema . name , field . fieldId , schema . version )
. catch ( error = > this . dialogs . notifyError ( error ) )
. catch ( error = > this . dialogs . notifyError ( error ) )
. do ( dto = > {
. do ( dto = > {
this . replaceSchema ( schema . updateField ( field . lock ( ) , this . user , dto . version ) ) ;
this . replaceSchema ( schema . updateField ( field . lock ( ) , this . user , dto . version ) ) ;
@ -132,7 +140,7 @@ export class SchemasState {
}
}
public showField ( schema : SchemaDetailsDto , field : FieldDto ) : Observable < any > {
public showField ( schema : SchemaDetailsDto , field : FieldDto ) : Observable < any > {
return this . schemasService . showField ( this . app , schema . name , field . fieldId , schema . version )
return this . schemasService . showField ( this . appName , schema . name , field . fieldId , schema . version )
. catch ( error = > this . dialogs . notifyError ( error ) )
. catch ( error = > this . dialogs . notifyError ( error ) )
. do ( dto = > {
. do ( dto = > {
this . replaceSchema ( schema . updateField ( field . show ( ) , this . user , dto . version ) ) ;
this . replaceSchema ( schema . updateField ( field . show ( ) , this . user , dto . version ) ) ;
@ -140,7 +148,7 @@ export class SchemasState {
}
}
public hideField ( schema : SchemaDetailsDto , field : FieldDto ) : Observable < any > {
public hideField ( schema : SchemaDetailsDto , field : FieldDto ) : Observable < any > {
return this . schemasService . hideField ( this . app , schema . name , field . fieldId , schema . version )
return this . schemasService . hideField ( this . appName , schema . name , field . fieldId , schema . version )
. catch ( error = > this . dialogs . notifyError ( error ) )
. catch ( error = > this . dialogs . notifyError ( error ) )
. do ( dto = > {
. do ( dto = > {
this . replaceSchema ( schema . updateField ( field . hide ( ) , this . user , dto . version ) ) ;
this . replaceSchema ( schema . updateField ( field . hide ( ) , this . user , dto . version ) ) ;
@ -148,7 +156,7 @@ export class SchemasState {
}
}
public deleteField ( schema : SchemaDetailsDto , field : FieldDto ) : Observable < any > {
public deleteField ( schema : SchemaDetailsDto , field : FieldDto ) : Observable < any > {
return this . schemasService . deleteField ( this . app , schema . name , field . fieldId , schema . version )
return this . schemasService . deleteField ( this . appName , schema . name , field . fieldId , schema . version )
. catch ( error = > this . dialogs . notifyError ( error ) )
. catch ( error = > this . dialogs . notifyError ( error ) )
. do ( dto = > {
. do ( dto = > {
this . replaceSchema ( schema . removeField ( field , this . user , dto . version ) ) ;
this . replaceSchema ( schema . removeField ( field , this . user , dto . version ) ) ;
@ -156,7 +164,7 @@ export class SchemasState {
}
}
public sortFields ( schema : SchemaDetailsDto , fields : FieldDto [ ] ) : Observable < any > {
public sortFields ( schema : SchemaDetailsDto , fields : FieldDto [ ] ) : Observable < any > {
return this . schemasService . putFieldOrdering ( this . app , schema . name , fields . map ( t = > t . fieldId ) , schema . version )
return this . schemasService . putFieldOrdering ( this . appName , schema . name , fields . map ( t = > t . fieldId ) , schema . version )
. catch ( error = > this . dialogs . notifyError ( error ) )
. catch ( error = > this . dialogs . notifyError ( error ) )
. do ( dto = > {
. do ( dto = > {
this . replaceSchema ( schema . replaceFields ( fields , this . user , dto . version ) ) ;
this . replaceSchema ( schema . replaceFields ( fields , this . user , dto . version ) ) ;
@ -164,7 +172,7 @@ export class SchemasState {
}
}
public updateField ( schema : SchemaDetailsDto , field : FieldDto , request : UpdateFieldDto ) : Observable < any > {
public updateField ( schema : SchemaDetailsDto , field : FieldDto , request : UpdateFieldDto ) : Observable < any > {
return this . schemasService . putField ( this . app , schema . name , field . fieldId , request , schema . version )
return this . schemasService . putField ( this . appName , schema . name , field . fieldId , request , schema . version )
. catch ( error = > this . dialogs . notifyError ( error ) )
. catch ( error = > this . dialogs . notifyError ( error ) )
. do ( dto = > {
. do ( dto = > {
this . replaceSchema ( schema . updateField ( field . update ( request . properties ) , this . user , dto . version ) ) ;
this . replaceSchema ( schema . updateField ( field . update ( request . properties ) , this . user , dto . version ) ) ;
@ -172,7 +180,7 @@ export class SchemasState {
}
}
public configureScripts ( schema : SchemaDetailsDto , request : UpdateSchemaScriptsDto ) : Observable < any > {
public configureScripts ( schema : SchemaDetailsDto , request : UpdateSchemaScriptsDto ) : Observable < any > {
return this . schemasService . putSchemaScripts ( this . app , schema . name , request , schema . version )
return this . schemasService . putSchemaScripts ( this . appName , schema . name , request , schema . version )
. catch ( error = > this . dialogs . notifyError ( error ) )
. catch ( error = > this . dialogs . notifyError ( error ) )
. do ( dto = > {
. do ( dto = > {
this . replaceSchema ( schema . configureScripts ( request , this . user , dto . version ) ) ;
this . replaceSchema ( schema . configureScripts ( request , this . user , dto . version ) ) ;
@ -180,7 +188,7 @@ export class SchemasState {
}
}
public update ( schema : SchemaDetailsDto , request : UpdateSchemaDto ) : Observable < any > {
public update ( schema : SchemaDetailsDto , request : UpdateSchemaDto ) : Observable < any > {
return this . schemasService . putSchema ( this . app , schema . name , request , schema . version )
return this . schemasService . putSchema ( this . appName , schema . name , request , schema . version )
. catch ( error = > this . dialogs . notifyError ( error ) )
. catch ( error = > this . dialogs . notifyError ( error ) )
. do ( dto = > {
. do ( dto = > {
this . replaceSchema ( schema . update ( request , this . user , dto . version ) ) ;
this . replaceSchema ( schema . update ( request , this . user , dto . version ) ) ;
@ -188,7 +196,7 @@ export class SchemasState {
}
}
public delete ( schema : SchemaDto ) : Observable < any > {
public delete ( schema : SchemaDto ) : Observable < any > {
return this . schemasService . deleteSchema ( this . app , schema . name , schema . version )
return this . schemasService . deleteSchema ( this . appName , schema . name , schema . version )
. catch ( error = > this . dialogs . notifyError ( error ) )
. catch ( error = > this . dialogs . notifyError ( error ) )
. do ( dto = > {
. do ( dto = > {
this . schemasItems . nextBy ( v = > v . filter ( s = > s . id !== schema . id ) ) ;
this . schemasItems . nextBy ( v = > v . filter ( s = > s . id !== schema . id ) ) ;
@ -198,7 +206,10 @@ export class SchemasState {
private replaceSchema ( schema : SchemaDto ) {
private replaceSchema ( schema : SchemaDto ) {
this . schemasItems . nextBy ( v = > v . replaceBy ( 'id' , schema ) ) ;
this . schemasItems . nextBy ( v = > v . replaceBy ( 'id' , schema ) ) ;
this . selectedSchema . nextBy ( v = > v !== null && v . id === schema . id ? < SchemaDetailsDto > schema : v ) ;
if ( schema instanceof SchemaDetailsDto ) {
this . selectedSchema . nextBy ( v = > v !== null && v . id === schema . id ? schema : v ) ;
this . selectedReferencedSchema . nextBy ( v = > v !== null && v . id === schema . id ? schema : v ) ;
}
}
}
public trackBySchema ( index : number , schema : SchemaDto ) : any {
public trackBySchema ( index : number , schema : SchemaDto ) : any {