Skip to content

Commit

Permalink
Bugfix/identifiers (#3914)
Browse files Browse the repository at this point in the history
* wip

* Fixed the APIs and added warning for no IDs DB

---------

Co-authored-by: Ramin Haeri Azad <[email protected]>
  • Loading branch information
kazoompa and Ramin Haeri Azad authored Sep 4, 2024
1 parent a93ade5 commit 892e09f
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ watch(
(value) => {
if (value) {
const total = props.identifier?.valueSetCount ?? 0;
identifiersStore.getMappingIdentifiersCount(props.identifier.name, props.mapping.name).then((count) => {
identifiersStore.getMappingIdentifiersCount(props.identifier.entityType, props.mapping.name).then((count) => {
initialized.value = true;
mappingIdentifiersCount.value = total - count;
});
Expand Down Expand Up @@ -175,7 +175,7 @@ async function onAddMapping() {
const valid = await formRef.value.validate();
if (valid) {
identifiersStore
.generateMapping(props.identifier.name, props.mapping.name, options.value)
.generateMapping(props.identifier.entityType, props.mapping.name, options.value)
.then(() => {
emit('update');
onHide();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ async function onImport() {
.addMapping(props.identifier.name, newMapping)
.then(() => {
identifiersStore
.importMappingSystemIdentifiers(props.identifier.name, mappingName.value ?? '', createCsvContent())
.importMappingSystemIdentifiers(props.identifier.entityType, mappingName.value ?? '', createCsvContent())
.then(() => {
emit('update');
onHide();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<q-card-section>
<div class="text-h6">{{ $t('id_mappings.add_identifier') }}</div>
</q-card-section>

<q-separator />

<q-card-section>
Expand Down Expand Up @@ -78,7 +78,7 @@ async function onImport() {
const valid = await formRef.value.validate();
if (valid) {
identifiersStore
.importSystemIdentifiers(props.identifier.name, systemIdentifiers.value)
.importSystemIdentifiers(props.identifier.entityType, systemIdentifiers.value)
.then(() => {
emit('update');
onHide();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ async function onMappingAdded() {
}
function onExportMappingIdentifiers(mappingName: string) {
window.open(`${baseUrl}/identifiers/mapping/${mappingName}/_export?type=${props.identifierTable.name}`);
window.open(`${baseUrl}/identifiers/mapping/${mappingName}/_export?type=${props.identifierTable.entityType}`);
}
function onOverRow(row: VariableDto) {
Expand Down
90 changes: 46 additions & 44 deletions opal-ui/src/i18n/en/index.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions opal-ui/src/i18n/fr/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ export default {
mapped_identifiers: 'Identifiants Correspondants',
import_table_sys_ids_info: 'La table dont les identifiants d\'entité seront copiés en tant qu\'identifiants système. Les nouveaux identifiants seront ajoutés, les existants seront ignorés.',
entity_type_no_tables: 'Il n\'y a pas de tables pour le type d\'entité \'{entityType}\'.',
no_database_warning: 'Aucune base de données d\'identifiants n\'est configurée.'
},
git: {
diff_viewer: {
Expand Down Expand Up @@ -781,6 +782,7 @@ export default {
comment: 'Commentaire',
compare: 'Comparer',
configuration: 'Configuration',
configure: 'Configurer',
configure_import_source: 'Configurer la source de données',
confirm: 'Confirmer',
content: 'Contenu',
Expand Down
26 changes: 23 additions & 3 deletions opal-ui/src/pages/AdminIdentifiersPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@
{{ $t('id_mappings.info') }}
</div>
</div>
<div class="row q-gutter-md">

<q-banner v-if="!hasIdsDatabase" inline-actions rounded class="bg-warning">
{{ $t('id_mappings.no_database_warning') }}

<template v-slot:action>
<q-btn flat :label="$t('configure')" to="/admin/databases" />
</template>
</q-banner>
<div v-else class="row q-gutter-md">
<div class="col">
<div class="text-h6 q-mb-md row q-gutter-sm items-center">
<span>{{ $t('id_mappings.ids_list_title') }}</span>
Expand Down Expand Up @@ -55,7 +63,7 @@
<div v-if="hasIdentifiersTables" class="col-9">
<div class="text-h6">
{{ selectedIdentifierTable?.entityType }}
<q-btn :label="$t('export')" color="secondary" icon="output" @click="onExportIdentifiers" size="sm"/>
<q-btn :label="$t('export')" color="secondary" icon="output" @click="onExportIdentifiers" size="sm" />
<q-btn-dropdown class="q-ml-sm" color="secondary" :label="$t('import')" icon="input" size="sm">
<q-list>
<q-item clickable v-close-popup @click.prevent="onImportSystemIdentifiersList">
Expand Down Expand Up @@ -152,9 +160,11 @@ const { t } = useI18n();
const loading = ref(false);
const tab = ref('mappings');
const systemStore = useSystemStore();
const identifiersStore = useIdentifiersStore();
const selectedIdentifierTable = ref({} as TableDto);
const confirm = ref({ title: '', text: '', onCallback: () => ({}) });
const hasIdsDatabase = ref(true);
const showConfirm = ref(false);
const showAddIdentifierTable = ref(false);
const showImportList = ref(false);
Expand Down Expand Up @@ -259,5 +269,15 @@ async function onMappingUpdated() {
getIdentifiersTables();
}
onMounted(() => getIdentifiersTables());
onMounted(() => {
systemStore
.getDatabasesStatus()
.then((status) => {
hasIdsDatabase.value = status.hasIdentifiers;
if (hasIdsDatabase.value) {
getIdentifiersTables();
}
})
.catch(notifyError);
});
</script>
16 changes: 8 additions & 8 deletions opal-ui/src/stores/identifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,21 @@ export const useIdentifiersStore = defineStore('identifiers', () => {
return api.delete(`/identifiers/table/${idTableName}/variable/${mappingName}`);
}

async function getMappingIdentifiersCount(idTableName: string, mappingName: string) {
async function getMappingIdentifiersCount(entityType: string, mappingName: string) {
return api
.get(`/identifiers/mapping/${mappingName}/_count`, { params: { type: idTableName } })
.get(`/identifiers/mapping/${mappingName}/_count`, { params: { type: entityType } })
.then((response) => response.data);
}

async function generateMapping(idTableName: string, mappingName: string, options: GenerateIdentifiersOptions) {
async function generateMapping(entityType: string, mappingName: string, options: GenerateIdentifiersOptions) {
return api.post(`/identifiers/mapping/${mappingName}/_generate`, null, {
params: { type: idTableName, ...options }
params: { type: entityType, ...options }
});
}

async function importSystemIdentifiers(idTableName: string, content: string, separator?: string) {
async function importSystemIdentifiers(entityType: string, content: string, separator?: string) {
return api.post('/identifiers/mapping/entities/_import', content, {
params: separator ? { type: idTableName, separator } : { type: idTableName },
params: separator ? { type: entityType, separator } : { type: entityType },
headers: { 'Content-Type': 'text/plain' },
});
}
Expand All @@ -91,13 +91,13 @@ export const useIdentifiersStore = defineStore('identifiers', () => {
}

async function importMappingSystemIdentifiers(
idTableName: string,
entityType: string,
mappingName: string,
content: string,
separator?: string
) {
return api.post(`/identifiers/mapping/${mappingName}/_import`, content, {
params: separator ? { type: idTableName, separator } : { type: idTableName },
params: separator ? { type: entityType, separator } : { type: entityType },
headers: { 'Content-Type': 'text/plain' },
});
}
Expand Down
7 changes: 6 additions & 1 deletion opal-ui/src/stores/system.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineStore } from 'pinia';
import { api } from 'src/boot/api';
import { DatabaseDto } from 'src/models/Database';
import { DatabaseDto, DatabasesStatusDto } from 'src/models/Database';
import { GeneralConf } from 'src/models/Opal';


Expand All @@ -21,6 +21,10 @@ export const useSystemStore = defineStore('system', () => {
return api.put('/system/conf/general', data).then(initGeneralConf);
}

async function getDatabasesStatus(): Promise<DatabasesStatusDto> {
return api.get('/system/status/databases').then((response) => response.data);
}

async function getDatabases(usage: string): Promise<DatabaseDto[]> {
return api.get('/system/databases', { params: { usage } }).then((response) => response.data);
}
Expand Down Expand Up @@ -53,6 +57,7 @@ export const useSystemStore = defineStore('system', () => {
generalConf,
initGeneralConf,
saveGeneralConf,
getDatabasesStatus,
getDatabases,
getDatabasesWithSettings,
getIdentifiersDatabase,
Expand Down

0 comments on commit 892e09f

Please sign in to comment.