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

Issue 816 #77

Closed
wants to merge 2 commits into from
Closed
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
38 changes: 23 additions & 15 deletions src/components/DatasetEditorForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,16 @@ export default defineComponent({
VCombobox
},
setup() {

const random6ASCIICharacters = () => {
let result = '';
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
for (let i = 0; i < 6; i++) {
result += characters.charAt(Math.floor(Math.random() * characters.length));
}
return result;
};

// Deep clone function to avoid reference issues between model and default model
function deepClone(obj) {
return JSON.parse(JSON.stringify(obj));
Expand Down Expand Up @@ -1409,15 +1419,14 @@ export default defineComponent({

// Method to check that the identifier does not already exist
const createAndCheckIdentifier = (identifier) => {
// Truncate data policy
let truncatedPolicy = model.value.identification.wmoDataPolicy.substring(0, 4);
let randomCode = random6ASCIICharacters();

// Replace centre ID and data policy
let id = identifier.replace(
'$CENTRE_ID', model.value.identification.centreID
).replace(
'$DATA_POLICY', truncatedPolicy
);
'$DATA_POLICY', randomCode
).replace(/\..*$/, '');

// If id already in items, inform the user that they will need to change the id in the form
if (items.value.includes(id)) {
Expand All @@ -1433,23 +1442,22 @@ export default defineComponent({
const replaceDataPolicyInIdentifier = () => {
let id = model.value.identification.identifier;

// Truncate policy to 4 letters
let truncatedPolicy = model.value.identification.wmoDataPolicy.substring(0, 4);
let randomCode = random6ASCIICharacters();

// Replace ':core.' or ':reco.' in the identifier
model.value.identification.identifier = id.replace(/:core\.|:reco\./g, `:${truncatedPolicy}.`);
model.value.identification.identifier = id.replace(/:(core|recommended)(\..*)?$/g, `:${randomCode}`);
};


// If the template is other and the data policy is changed,
// replace the data policy in the topic hierarchy
const replaceDataPolicyInTopicHierarchy = () => {
let policy = model.value.identification.wmoDataPolicy;
let randomCode = random6ASCIICharacters();
let hierarcy = model.value.identification.topicHierarchy;

// Replace 'core' or 'recommended' in the topic hierachy
// string with the policy
model.value.identification.topicHierarchy = hierarcy.replace(/core|recommended/g, policy);
model.value.identification.topicHierarchy = hierarcy.replace(/(core|recommended)(\..*)?$/g, randomCode);
};

// Autofill form based on template
Expand All @@ -1464,7 +1472,8 @@ export default defineComponent({
// Use centre ID and WMO data policy to create topic hierarchy
model.value.identification.topicHierarchy = template.topicHierarchy
.replace('$CENTRE_ID', model.value.identification.centreID)
.replace('$DATA_POLICY', model.value.identification.wmoDataPolicy);
.replace('$DATA_POLICY', randomCode)
.replace(/\..*$/, '');
// Get resolution and resolution unit from template
const match = template.resolution.match(/P(\d+)([DH])/i);
if (match) {
Expand Down Expand Up @@ -1525,11 +1534,10 @@ export default defineComponent({
return;
}

// Otherwise, create sensible defaults using centre ID and policy
let policy = model.value.identification.wmoDataPolicy;
let truncatedPolicy = policy.substring(0, 4);
// Otherwise, create sensible defaults using centre ID and randomcode
let randomCode = random6ASCIICharacters();
let centreID = model.value.identification.centreID;
model.value.identification.identifier = 'urn:wmo:md:' + centreID + ':' + truncatedPolicy + '.';
model.value.identification.identifier = 'urn:wmo:md:' + centreID + ':' + randomCode;
model.value.identification.topicHierarchy = centreID + '/data/' + policy + '/';
}

Expand Down Expand Up @@ -2301,4 +2309,4 @@ export default defineComponent({
text-align: right;
vertical-align: middle;
}
</style>
</style>
Loading