Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add function of automatically convert to lowercase of local ID #81

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 29 additions & 11 deletions src/components/DatasetEditorForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,19 @@
</v-row>
<v-row dense>
<v-col cols="12">
<v-text-field label="Local ID" type="string" v-model="localID" @input="updateIdentifierFromLocalID" variant="outlined" clearable :disabled="isEditing"></v-text-field>
<v-text-field label="Local ID" type="string" v-model="localID" @input="updateIdentifierFromLocalID" variant="outlined" @update:modelValue="convertToLowercaseLocalID" clearable :disabled="isEditing"></v-text-field>
</v-col>
</v-row>
</v-col>

<v-col cols="6">
<v-textarea label="Description"
placeholder="Please enter a detailed description of the dataset" type="string"
v-model="model.identification.description" :rules="[rules.required]" variant="outlined"
clearable></v-textarea>
</v-col>

<v-col cols="12">
<v-row dense>
<v-col cols="11">
<v-text-field label="Identifier" type="string"
Expand All @@ -132,13 +142,6 @@
</v-col>
</v-row>
</v-col>

<v-col cols="6">
<v-textarea label="Description"
placeholder="Please enter a detailed description of the dataset" type="string"
v-model="model.identification.description" :rules="[rules.required]" variant="outlined"
clearable></v-textarea>
</v-col>
</v-row>
<v-row>
</v-row>
Expand All @@ -155,7 +158,7 @@
<!-- Unless the user selects 'other' for the datatype
label, the topic hierarchy should remain disabled as
it is autofilled -->
<v-col cols="6">
<v-col cols="8">
<v-text-field label="Topic Hierarchy" type="string"
v-model="model.identification.topicHierarchy" :rules="[rules.required]"
variant="outlined" :disabled="selectedTemplate?.label !== 'other'"></v-text-field>
Expand Down Expand Up @@ -824,7 +827,7 @@ export default defineComponent({

const random6ASCIICharacters = () => {
let result = '';
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
for (let i = 0; i < 6; i++) {
result += characters.charAt(Math.floor(Math.random() * characters.length));
}
Expand Down Expand Up @@ -1035,6 +1038,18 @@ export default defineComponent({
model.value.identification.centreID = value.toLowerCase();
};


const convertToLowercaseLocalID = (value) => {
if (!value) {
localID.value = '';
return;
}
localID.value = value
.trim()
.toLowerCase()
.replace(/\s+/g, '-');
};

// Has the user filled the dialog window?
const initialDialogFilled = computed(() => {
return model.value.identification.centreID && selectedTemplate.value;
Expand Down Expand Up @@ -1528,6 +1543,7 @@ export default defineComponent({
// Metadata Editor parts
model.value.identification.title = template.title.replace('$CENTRE_ID', model.value.identification.centreID);
model.value.identification.identifier = createAndCheckIdentifier(template.identifier);
localID.value = extractLocalID(model.value.identification.identifier);
// Converts the theme structure into a list of the theme labels
model.value.identification.concepts = template.themes.flatMap(theme => theme.concepts.map(concept => concept.label));
model.value.identification.conceptScheme = template.themes.map(theme => theme.scheme)[0];
Expand Down Expand Up @@ -1602,6 +1618,7 @@ export default defineComponent({
let policy = model.value.identification.wmoDataPolicy;
let centreID = model.value.identification.centreID;
model.value.identification.identifier = 'urn:wmo:md:' + centreID + ':' + randomCode;
localID.value = extractLocalID(model.value.identification.identifier);
model.value.identification.topicHierarchy = centreID + '/data/' + policy + '/';
}

Expand Down Expand Up @@ -2361,7 +2378,8 @@ export default defineComponent({
updateIdentifierFromLocalID,
extractLocalID,
localID,
isEditing
isEditing,
convertToLowercaseLocalID
}
}
});
Expand Down
Loading