Skip to content

Commit

Permalink
fixed adjustable parameters for new setups and other bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
hvarg committed Dec 3, 2019
1 parent a379ba8 commit f8fb016
Show file tree
Hide file tree
Showing 5 changed files with 378 additions and 123 deletions.
7 changes: 5 additions & 2 deletions src/model-catalog/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export * from './region-actions';
export * from './process-actions';
export * from './parameter-actions';
export * from './model-configuration-actions';
export * from './model-configuration-setup-actions';
export * from './dataset-specification-actions';
export * from './sample-resource-actions';
export * from './sample-collection-actions';
Expand All @@ -21,6 +22,7 @@ import { ModelCatalogGeoShapeAction } from './geo-shape-actions';
import { ModelCatalogParameterAction } from './parameter-actions';
import { ModelCatalogProcessAction } from './process-actions';
import { ModelCatalogModelConfigurationAction } from './model-configuration-actions';
import { ModelCatalogModelConfigurationSetupAction } from './model-configuration-setup-actions';
import { ModelCatalogDatasetSpecificationAction } from './dataset-specification-actions';
import { ModelCatalogSampleResourceAction } from './sample-resource-actions';
import { ModelCatalogSampleCollectionAction } from './sample-collection-actions';
Expand All @@ -42,7 +44,7 @@ export const fixPosition = (resource:any) => {
}

export const fixObjects = (collection:any[]) => {
return collection.map(s => typeof s === "string" ? {id: s} : s);
return (collection||[]).map(s => typeof s === "string" ? {id: s} : s);
}

export const isValidId = (id:string) => typeof id === 'string' && id.includes(PREFIX_URI);
Expand Down Expand Up @@ -176,7 +178,8 @@ export const softwareImageGet: ActionCreator<ModelCatalogThunkResult> = (uri) =>
export type ModelCatalogAction = MCACommon | ModelCatalogPersonAction | ModelCatalogParameterAction | ModelCatalogProcessAction |
ModelCatalogModelConfigurationAction | ModelCatalogRegionAction | ModelCatalogSampleCollectionAction |
ModelCatalogSampleResourceAction | ModelCatalogDatasetSpecificationAction |
MCAModelsGet | MCAVersionsGet | ModelCatalogGeoShapeAction |
MCAModelsGet | MCAVersionsGet | ModelCatalogGeoShapeAction
|ModelCatalogModelConfigurationSetupAction |
MCAGridGet | MCATimeIntervalGet | MCASoftwareImageGet;

type ModelCatalogThunkResult = ThunkAction<void, RootState, undefined, ModelCatalogAction>;
83 changes: 34 additions & 49 deletions src/model-catalog/model-configuration-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,23 @@ export const modelConfigurationsGet: ActionCreator<ModelCatalogModelConfiguratio
dispatch({type: START_LOADING, id: ALL_MODEL_CONFIGURATIONS});

let api : ModelConfigurationApi = new ModelConfigurationApi();
api.modelconfigurationsGet({username: DEFAULT_GRAPH})
.then((data) => {
dispatch({
type: MODEL_CONFIGURATIONS_GET,
payload: data.reduce(idReducer, {})
});
dispatch({type: END_LOADING, id: ALL_MODEL_CONFIGURATIONS});
let req : Promise<ModelConfiguration[]> = api.modelconfigurationsGet({username: DEFAULT_GRAPH});
req.then((data) => {
data = data.map(m => {
return { ...m,
contributor: fixObjects(m.contributor),
author: fixObjects(m.author),
hasOutput: fixObjects(m.hasOutput)
}
})
.catch((err) => {console.log('Error on GET modelConfigurations', err)})
dispatch({
type: MODEL_CONFIGURATIONS_GET,
payload: data.reduce(idReducer, {})
});
dispatch({type: END_LOADING, id: ALL_MODEL_CONFIGURATIONS});
});
req.catch((err) => {console.log('Error on GET modelConfigurations', err)})
return req;
}

export const MODEL_CONFIGURATION_GET = "MODEL_CONFIGURATION_GET";
Expand Down Expand Up @@ -87,6 +95,7 @@ export const modelConfigurationPost: ActionCreator<PostConfigThunk> = (modelConf
let uri = PREFIX_URI + resp.id;
let data = {};
resp.id = uri;
resp['isAdjustable'] = parameter['isAdjustable'];
data[uri] = resp;
newParameters.push(resp);
if (!isFixed) adjustableParameters.push(resp);
Expand Down Expand Up @@ -150,7 +159,6 @@ export const modelConfigurationPost: ActionCreator<PostConfigThunk> = (modelConf
reject(err);
});
});

}));
} else {
let req = sampleResourceApi.sampleresourcesPost({user: DEFAULT_GRAPH, sampleResource: sample});
Expand Down Expand Up @@ -210,6 +218,7 @@ export const modelConfigurationPost: ActionCreator<PostConfigThunk> = (modelConf
//FIXME: this is not working, maybe we should use other class to create ModelConfigurationSetup or ConfigurationSetup
//modelConfiguration.adjustableParameter = adjustableParameters;
modelConfiguration.hasParameter = newParameters;
console.log('adjs', newParameters.filter(p => p.isAdjustable));
modelConfiguration.hasInput = newDS;
console.log('SS', modelConfiguration)
let api : ModelConfigurationApi = new ModelConfigurationApi(cfg);
Expand Down Expand Up @@ -243,58 +252,34 @@ export const modelConfigurationPost: ActionCreator<PostConfigThunk> = (modelConf
console.error('POST setup failed!', err);
});
}

/*if (status === 'DONE') {
dispatch({type: START_POST, id: identifier});
modelConfiguration.id = undefined;
let api : ModelConfigurationApi = new ModelConfigurationApi(cfg);
api.modelconfigurationsPost({user: DEFAULT_GRAPH, modelConfiguration: modelConfiguration}) // This should be my username on prod.
.then((resp) => {
console.log('Response for POST modelConfiguration:', resp);
//Its returning the ID without the prefix
let uri = PREFIX_URI + resp.id;
let data = {};
data[uri] = resp;
resp.id = uri;
dispatch({
type: MODEL_CONFIGURATION_GET,
payload: data
});
dispatch({type: END_POST, id: identifier, uri: uri});
})
.catch((err) => {console.log('Error on POST modelConfiguration', err)})
} else if (status === 'LOADING') {
repeatAction(modelConfigurationPost, modelConfiguration);
}*/
}

export const MODEL_CONFIGURATION_PUT = "MODEL_CONFIGURATION_PUT";
interface MCAModelConfigurationPut extends Action<'MODEL_CONFIGURATION_PUT'> { payload: any };
export const modelConfigurationPut: ActionCreator<ModelCatalogModelConfigurationThunkResult> = ( modelConfiguration: ModelConfiguration ) => (dispatch) => {
debug('updating modelConfiguration', modelConfiguration.id);
debug('updating modelConfiguration', modelConfiguration);
let status : string, cfg : Configuration, user : string;
[status, cfg, user] = getStatusConfigAndUser();

if (status === 'DONE') {
dispatch({type: START_LOADING, id: modelConfiguration.id});
let api : ModelConfigurationApi = new ModelConfigurationApi(cfg);
let id : string = modelConfiguration.id.split('/').pop();
modelConfiguration.author = fixObjects(modelConfiguration.author);
modelConfiguration.hasOutput = fixObjects(modelConfiguration.hasOutput);
api.modelconfigurationsIdPut({id: id, user: DEFAULT_GRAPH, modelConfiguration: modelConfiguration}) // This should be my username on prod.
.then((resp) => {
console.log('Response for PUT modelConfiguration:', resp);
let data = {};
data[modelConfiguration.id] = resp;
dispatch({
type: MODEL_CONFIGURATION_GET,
payload: data
});
dispatch({type: END_LOADING, id: modelConfiguration.id});
})
.catch((err) => {console.log('Error on PUT modelConfiguration', err)})
} else if (status === 'LOADING') {
repeatAction(modelConfigurationPut, modelConfiguration);
let req : Promise<ModelConfiguration> = api.modelconfigurationsIdPut({id: id, user: DEFAULT_GRAPH, modelConfiguration: modelConfiguration}) // This should be my username on prod.
req.then((resp) => {
console.log('Response for PUT modelConfiguration:', resp);
let data = {};
data[modelConfiguration.id] = resp;
dispatch({
type: MODEL_CONFIGURATION_GET,
payload: data
});
dispatch({type: END_LOADING, id: modelConfiguration.id});
});
req.catch((err) => {console.log('Error on PUT modelConfiguration', err)});
return req;
} else {
console.error('Token', status);
}
}

Expand Down
Loading

0 comments on commit f8fb016

Please sign in to comment.