Skip to content

Commit

Permalink
devs on import confiance
Browse files Browse the repository at this point in the history
  • Loading branch information
BertrandRenault committed Feb 21, 2023
1 parent 6829d87 commit a0ba4ea
Show file tree
Hide file tree
Showing 6 changed files with 432 additions and 353 deletions.
115 changes: 1 addition & 114 deletions frontend/src/views/app-datasets-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ import {
importDataset,
createDatasetFrom,
importFromKafka,
projsFromDP,
selectionsFromDP,
id_listFromDP,
minio_urisFromDP,
deleteDataset
} from '../actions/media';

Expand All @@ -51,9 +47,7 @@ class AppDatasetsManager extends connect(store)(TemplatePage) {
datasetIdx: { type: Number },
pathOrURL: { type: String },
nbSelectedRows: { type: Number },
items: { type: Array },
dialog_projsel_template: { type: Array },
dialog_selsel_template: { type: Array }
items: { type: Array }
};
}

Expand All @@ -64,7 +58,6 @@ class AppDatasetsManager extends connect(store)(TemplatePage) {
this.pathOrURL = "undetermined";
this.default_path = "";
this.nbSelectedRows = 0;
this.dialog_projsel_template = null;

// ELISE
this.similarityLevel = 0;//similarity in %
Expand Down Expand Up @@ -289,83 +282,6 @@ class AppDatasetsManager extends connect(store)(TemplatePage) {
.catch(error => this.errorPopup(error.message));
}

/**
* Fired when clic on import from DP
*/
async onImportFromDP() {
store.dispatch(projsFromDP()).then((projs) => {
console.log("projsFromDP", projs);
//project selector
this.project_list = projs;
if (Object.entries(projs).length > 0) {
this.fillProjectList(projs);
} else { this.errorPopup("No available project !") }
}).catch(error => this.errorPopup(error.message));
}

fillProjectList(projs) {
this.dialog_projsel_template = []
for (const [key, _] of Object.entries(projs)) {
this.dialog_projsel_template.push(html`<mwc-list-item dialogAction='ok'>${key}</mwc-list-item>`);
};
const projSelectorElem = this.shadowRoot.getElementById('dialog-project-selector');
console.log("SelectorElement", projSelectorElem)
projSelectorElem.open = true;
}

fillSelectionList(sels) {
this.dialog_selsel_template = []
for (const [_, value] of Object.entries(sels)) {
this.dialog_selsel_template.push(html`<mwc-list-item twoline dialogAction='ok'>
<span>${value.name}</span>
<span slot='secondary'>id: ${value.id}, nb_samples: ${value.nbSamples}</span></mwc-list-item>`);

};
const selSelectorElem = this.shadowRoot.getElementById('dialog-selection-selector');
selSelectorElem.open = true;
}

onProjectSelected(selected) {
const proj = this.project_list[Object.keys(this.project_list)[selected.detail.index]]
this.project_name = proj.name;
console.log(" selected project: ", this.project_name);

store.dispatch(selectionsFromDP(this.project_name)).then((sels) => {
console.log("selectionsFromDP", sels);
//selection selector
this.selection_list = sels;

if (this.selection_list.length > 0) {
this.fillSelectionList(this.selection_list);
} else { this.errorPopup("No available selection !")}
}).catch(error => this.errorPopup(error.message));
}

onSelectionSelected(selected) {
const sel = this.selection_list[Object.keys(this.selection_list)[selected.detail.index]]
console.log(" selected selection full:", sel);
console.log(" selected selection:", sel.id);
store.dispatch(id_listFromDP(this.project_name, sel)).then((newtask) => {
console.log("id_listFromDP", newtask);
this.datasetIdx = this.datasets.length;//select the newly created dataset
this.onActivate();
// update local copy of Redux
this.tasks = getState('application').tasks;
this.taskIdx = getState('application').tasks.findIndex((t) => t.name === getState('application').taskName);
}).catch(error => {
this.errorPopup(error.message)
});

/***
//tmp test... maintenant on crée une task, pas juste un dataset, alors faut gerer différemment (voire tout deplacer dans tasks.js ?)
store.dispatch(importTaskFromKafka(task)).then((newtask) => {
// update local copy of Redux
this.tasks = getState('application').tasks;
this.taskIdx = getState('application').tasks.findIndex((t) => t.name === getState('application').taskName);
}).catch((error) => this.errorPopup(error.message));
**/
}

/**
* Fired when user wants to delete a dataset.
*/
Expand Down Expand Up @@ -695,14 +611,6 @@ class AppDatasetsManager extends connect(store)(TemplatePage) {
@click="${this.onImportFromKafka}">
Import from Kafka
</mwc-button>
<mwc-button outlined
class="newDataset"
type="button"
icon="add"
title="Import a new dataset from DebiAI DP"
@click="${this.onImportFromDP}">
Import from DebiAI
</mwc-button>
`;
}

Expand Down Expand Up @@ -850,27 +758,6 @@ class AppDatasetsManager extends connect(store)(TemplatePage) {
</mwc-dialog>
`;
}

get dialogProjectSelector() {
return html`
<mwc-dialog heading="Select a project" id="dialog-project-selector">
<mwc-list id='list-project-selector' @action=${this.onProjectSelected} style="height: 55vh; overflow-y: auto;">
${this.dialog_projsel_template}
</mwc-list>
</mwc-dialog>
`;
}

get dialogSelectionSelector() {
return html`
<mwc-dialog heading="Select a selection" id="dialog-selection-selector">
<mwc-list id='list-selection-selector' @action=${this.onSelectionSelected} style="height: 55vh; overflow-y: auto;">
${this.dialog_selsel_template}
</mwc-list>
</mwc-dialog>
`;
}

}
customElements.define('app-datasets-manager', AppDatasetsManager);

105 changes: 104 additions & 1 deletion frontend/src/views/app-project-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import '@material/mwc-tab';
import '@material/mwc-tab-bar';
import '@material/mwc-textfield';
import '@material/mwc-select';
import '@material/mwc-list/mwc-list';
import '@material/mwc-list/mwc-list-item';
import '@material/mwc-switch';
import '@trystan2k/fleshy-jsoneditor/fleshy-jsoneditor.js';
Expand All @@ -34,7 +35,12 @@ import {
putTask,
getTasks
} from '../actions/application';
import { getDatasets } from '../actions/media';
import {
getDatasets,
projsFromDP,
selectionsFromDP,
id_listFromDP
} from '../actions/media';


class AppProjectManager extends connect(store)(TemplatePage) {
Expand All @@ -45,6 +51,8 @@ class AppProjectManager extends connect(store)(TemplatePage) {
creatingTask: { type: Boolean },
importExportText: { type: String },
pathOrURL: { type: String },
dialog_projsel_template: { type: Array },
dialog_selsel_template: { type: Array }
};
}

Expand All @@ -65,6 +73,7 @@ class AppProjectManager extends connect(store)(TemplatePage) {
this.pathOrURL = "undetermined";
this.default_path = "";
this.datasetIds = [];
this.dialog_projsel_template = null;
}

onActivate() {
Expand Down Expand Up @@ -112,6 +121,74 @@ class AppProjectManager extends connect(store)(TemplatePage) {
browserElem.open = true;
}

/**
* Fired when clic on import from DP
*/
onImportFromDP() {
store.dispatch(projsFromDP()).then((projs) => {
console.log("projsFromDP", projs);
//project selector
this.project_list = projs;
if (Object.entries(projs).length > 0) {
this.fillProjectList(projs);
} else { this.errorPopup("No available project !") }
}).catch(error => this.errorPopup(error.message));
}

fillProjectList(projs) {
this.dialog_projsel_template = []
for (const [key, val] of Object.entries(projs)) {
this.dialog_projsel_template.push(html`<mwc-list-item twoline dialogAction='ok'>
<span>${key}</span>
<span slot='secondary'>nb_samples: ${val.nbSamples}, nb_sel: ${val.nbSelections}</span></mwc-list-item>`);
};
const projSelectorElem = this.shadowRoot.getElementById('dialog-project-selector');
console.log("SelectorElement", projSelectorElem)
projSelectorElem.open = true;
}

fillSelectionList(sels) {
this.dialog_selsel_template = []
for (const [_, value] of Object.entries(sels)) {
this.dialog_selsel_template.push(html`<mwc-list-item twoline dialogAction='ok'>
<span>${value.name}</span>
<span slot='secondary'>id: ${value.id}, nb_samples: ${value.nbSamples}</span></mwc-list-item>`);

};
const selSelectorElem = this.shadowRoot.getElementById('dialog-selection-selector');
selSelectorElem.open = true;
}

onProjectSelected(selected) {
const proj = this.project_list[Object.keys(this.project_list)[selected.detail.index]]
this.project_name = proj.name;
console.log(" selected project: ", this.project_name);

store.dispatch(selectionsFromDP(this.project_name)).then((sels) => {
console.log("selectionsFromDP", sels);
//selection selector
this.selection_list = sels;

if (this.selection_list.length > 0) {
this.fillSelectionList(this.selection_list);
} else { this.errorPopup("No available selection !")}
}).catch(error => this.errorPopup(error.message));
}

onSelectionSelected(selected) {
const sel = this.selection_list[Object.keys(this.selection_list)[selected.detail.index]]
console.log(" selected selection full:", sel);
console.log(" selected selection:", sel.id);
store.dispatch(id_listFromDP(this.project_name, sel)).then(() => {
store.dispatch(getTasks()).then(() => {
this.onActivate();
})
}).catch(error => {
this.errorPopup(error.message);
store.dispatch(getTasks());
});
}

/**
* Fired when exporting a project
*/
Expand Down Expand Up @@ -338,6 +415,11 @@ class AppProjectManager extends connect(store)(TemplatePage) {
type="button"
title="Import annotations from json files"
@click="${this.onImport}">Import from files</mwc-button>
<mwc-button outlined
class="newDataset"
type="button"
title="Import a new dataset from Confiance DataBase"
@click="${this.onImportFromDP}">Import from Confiance DB</mwc-button>
</div>
</div>
`;
Expand Down Expand Up @@ -482,6 +564,27 @@ class AppProjectManager extends connect(store)(TemplatePage) {
</div>
</div>
</mwc-dialog>
${this.dialogProjectSelector}
${this.dialogSelectionSelector}
`;
}
get dialogProjectSelector() {
return html`
<mwc-dialog heading="Select a project" id="dialog-project-selector">
<mwc-list id='list-project-selector' @action=${this.onProjectSelected} style="height: 55vh; overflow-y: auto;">
${this.dialog_projsel_template}
</mwc-list>
</mwc-dialog>
`;
}

get dialogSelectionSelector() {
return html`
<mwc-dialog heading="Select a selection" id="dialog-selection-selector">
<mwc-list id='list-selection-selector' @action=${this.onSelectionSelected} style="height: 55vh; overflow-y: auto;">
${this.dialog_selsel_template}
</mwc-list>
</mwc-dialog>
`;
}
}
Expand Down
7 changes: 3 additions & 4 deletions server/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ const { get_datasets,
post_datasets,
post_dataset_from,
import_dataset_from_kafka,
projects_from_dataprovider,
selections_from_dataprovider,
id_list_from_dataprovider,
minio_uris_from_dataprovider,
get_dataset,
delete_dataset,
get_data,
Expand All @@ -41,6 +37,9 @@ const { get_tasks,
put_task,
delete_task,
import_tasks,
projects_from_dataprovider,
selections_from_dataprovider,
id_list_from_dataprovider,
export_tasks } = require('./routes/tasks');
const { snapshot_project } = require('./routes/project');
const { get_results,
Expand Down
Loading

0 comments on commit a0ba4ea

Please sign in to comment.