Skip to content

Commit

Permalink
Merge pull request #2178 from huridocs/translations-type-on-update
Browse files Browse the repository at this point in the history
Translations context now saves the type also on update
  • Loading branch information
daneryl authored Feb 15, 2019
2 parents 7133b62 + c87d84e commit 43f4660
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 28 deletions.
5 changes: 3 additions & 2 deletions app/api/i18n/translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export default {
});
},

updateContext(id, newContextName, keyNamesChanges, deletedProperties, values) {
updateContext(id, newContextName, keyNamesChanges, deletedProperties, values, type) {
const translatedValues = [];
Object.keys(values).forEach((key) => {
translatedValues.push({ key, value: values[key] });
Expand All @@ -127,12 +127,13 @@ export default {
return Promise.all(translations.map((translation) => {
const context = translation.contexts.find(tr => tr.id.toString() === id.toString());
if (!context) {
translation.contexts.push({ id, label: newContextName, values: translatedValues });
translation.contexts.push({ id, label: newContextName, values: translatedValues, type });
return this.save(translation);
}

context.values = context.values || [];
context.values = context.values.filter(v => !deletedProperties.includes(v.key));
context.type = type;

Object.keys(keyNamesChanges).forEach((originalKey) => {
const newKey = keyNamesChanges[originalKey];
Expand Down
2 changes: 1 addition & 1 deletion app/api/relationtypes/relationtypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const updateTranslation = (currentTemplate, template) => {

context[template.name] = template.name;

return translations.updateContext(currentTemplate._id, template.name, updatedLabels, deletedPropertiesByLabel, context);
return translations.updateContext(currentTemplate._id, template.name, updatedLabels, deletedPropertiesByLabel, context, 'Connection');
};

function _update(newTemplate) {
Expand Down
18 changes: 9 additions & 9 deletions app/api/relationtypes/specs/relationtypes.spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import relationtypes from '../relationtypes.js';
import {catchErrors} from 'api/utils/jasmineHelpers';
import { catchErrors } from 'api/utils/jasmineHelpers';
import translations from 'api/i18n/translations';

import db from 'api/utils/testing_db';
import fixtures, {canNotBeDeleted, against} from './fixtures.js';
import fixtures, { canNotBeDeleted, against } from './fixtures.js';

describe('relationtypes', () => {
beforeEach((done) => {
Expand Down Expand Up @@ -44,7 +44,7 @@ describe('relationtypes', () => {
});

it('should generate names and ids for the properties', (done) => {
relationtypes.save({name: 'Indiferent', properties: [{label: 'Property one'}]})
relationtypes.save({ name: 'Indiferent', properties: [{ label: 'Property one' }] })
.then((result) => {
expect(result.properties[0].name).toBe('property_one');
expect(result.properties[0]._id).toBeDefined();
Expand All @@ -55,7 +55,7 @@ describe('relationtypes', () => {

describe('when the relation type did not exist', () => {
it('should create a new one and return it', (done) => {
relationtypes.save({name: 'Indiferent', properties: []})
relationtypes.save({ name: 'Indiferent', properties: [] })
.then((result) => {
expect(result.name).toBe('Indiferent');
done();
Expand All @@ -64,9 +64,9 @@ describe('relationtypes', () => {
});

it('should create a new translation for it', (done) => {
relationtypes.save({name: 'Indiferent', properties: []})
relationtypes.save({ name: 'Indiferent', properties: [] })
.then((response) => {
expect(translations.addContext).toHaveBeenCalledWith(response._id, 'Indiferent', {Indiferent: 'Indiferent'}, 'Connection');
expect(translations.addContext).toHaveBeenCalledWith(response._id, 'Indiferent', { Indiferent: 'Indiferent' }, 'Connection');
done();
}).catch(catchErrors(done));
});
Expand All @@ -93,7 +93,7 @@ describe('relationtypes', () => {
return relationtypes.save(relationtype);
})
.then((response) => {
expect(translations.updateContext).toHaveBeenCalledWith(response._id, 'Pro', {Against: 'Pro'}, [], {Pro: 'Pro'});
expect(translations.updateContext).toHaveBeenCalledWith(response._id, 'Pro', { Against: 'Pro' }, [], { Pro: 'Pro' }, 'Connection');
done();
})
.catch(catchErrors(done));
Expand All @@ -102,7 +102,7 @@ describe('relationtypes', () => {

describe('when its duplicated', () => {
it('should return an error', (done) => {
let relationtype = {name: 'Against', properties: []};
const relationtype = { name: 'Against', properties: [] };
return relationtypes.save(relationtype)
.then(catchErrors(done))
.catch((error) => {
Expand All @@ -123,7 +123,7 @@ describe('relationtypes', () => {
expect(result).toBe(true);
return relationtypes.getById(against);
})
.then((response) =>{
.then((response) => {
expect(response).toBe(null);
done();
});
Expand Down
4 changes: 2 additions & 2 deletions app/api/settings/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function saveLinksTranslations(newLinks = [], currentLinks = []) {
return result;
}, {});

return translations.updateContext('Menu', 'Menu', updatedTitles, deletedLinks, values);
return translations.updateContext('Menu', 'Menu', updatedTitles, deletedLinks, values, 'Uwazi UI');
}

function saveFiltersTranslations(_newFilters = [], _currentFilters = []) {
Expand All @@ -46,7 +46,7 @@ function saveFiltersTranslations(_newFilters = [], _currentFilters = []) {
return result;
}, {});

return translations.updateContext('Filters', 'Filters', updatedNames, deletedFilters, values);
return translations.updateContext('Filters', 'Filters', updatedNames, deletedFilters, values, 'Uwazi UI');
}

function removeTemplate(filters, templateId) {
Expand Down
27 changes: 18 additions & 9 deletions app/api/settings/specs/settings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('settings', () => {
const config = { site_name: 'My collection', links: [{ title: 'Page one' }] };
settings.save(config)
.then(() => {
expect(translations.updateContext).toHaveBeenCalledWith('Menu', 'Menu', {}, [], { 'Page one': 'Page one' });
expect(translations.updateContext).toHaveBeenCalledWith('Menu', 'Menu', {}, [], { 'Page one': 'Page one' }, 'Uwazi UI');
done();
})
.catch(catchErrors(done));
Expand All @@ -60,7 +60,14 @@ describe('settings', () => {
})
.then(() => {
expect(translations.updateContext)
.toHaveBeenCalledWith('Menu', 'Menu', { 'Page one': 'Page 1' }, ['Page two'], { 'Page 1': 'Page 1', 'Page three': 'Page three' });
.toHaveBeenCalledWith(
'Menu',
'Menu',
{ 'Page one': 'Page 1' },
['Page two'],
{ 'Page 1': 'Page 1', 'Page three': 'Page three' },
'Uwazi UI'
);
done();
})
.catch(catchErrors(done));
Expand All @@ -77,7 +84,7 @@ describe('settings', () => {
};
settings.save(config)
.then(() => {
expect(translations.updateContext).toHaveBeenCalledWith('Filters', 'Filters', {}, [], { Documents: 'Documents' });
expect(translations.updateContext).toHaveBeenCalledWith('Filters', 'Filters', {}, [], { Documents: 'Documents' }, 'Uwazi UI');
done();
})
.catch(catchErrors(done));
Expand All @@ -96,13 +103,15 @@ describe('settings', () => {
})
.then(() => {
expect(translations.updateContext)
.toHaveBeenCalledWith('Menu', 'Menu', {}, [], {});
.toHaveBeenCalledWith('Menu', 'Menu', {}, [], {}, 'Uwazi UI');
expect(translations.updateContext)
.toHaveBeenCalledWith('Filters', 'Filters', {
Documents: 'Important Documents'
}, ['Files'], {
'Important Documents': 'Important Documents'
});
.toHaveBeenCalledWith(
'Filters',
'Filters', { Documents: 'Important Documents' },
['Files'],
{ 'Important Documents': 'Important Documents' },
'Uwazi UI'
);
done();
})
.catch(catchErrors(done));
Expand Down
3 changes: 2 additions & 1 deletion app/api/templates/specs/templates.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ describe('templates', () => {
'created template': 'new title'
},
['label 2'],
{ 'new label 1': 'new label 1', 'label 3': 'label 3', 'new title': 'new title' }
{ 'new label 1': 'new label 1', 'label 3': 'label 3', 'new title': 'new title' },
'Entity'
);
done();
})
Expand Down
2 changes: 1 addition & 1 deletion app/api/templates/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const updateTranslation = (currentTemplate, template) => {

context[template.name] = template.name;

return translations.updateContext(currentTemplate._id, template.name, updatedLabels, deletedPropertiesByLabel, context);
return translations.updateContext(currentTemplate._id, template.name, updatedLabels, deletedPropertiesByLabel, context, 'Entity');
};

const save = template => checkDuplicated(template)
Expand Down
3 changes: 2 additions & 1 deletion app/api/thesauris/specs/thesauris.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ describe('thesauris', () => {
'Top 1 games',
{ 'Enders game': 'Marios game', 'Top 2 scify books': 'Top 1 games' },
['Fundation'],
{ 'Top 1 games': 'Top 1 games', 'Marios game': 'Marios game' }
{ 'Top 1 games': 'Top 1 games', 'Marios game': 'Marios game' },
'Dictionary'
);
done();
})
Expand Down
3 changes: 1 addition & 2 deletions app/api/thesauris/thesauris.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ const updateTranslation = (current, thesauri) => {
const context = thesauriToTranslatioNContext(thesauri);

context[thesauri.name] = thesauri.name;

return translations.updateContext(current._id, thesauri.name, updatedLabels, deletedPropertiesByLabel, context);
return translations.updateContext(current._id, thesauri.name, updatedLabels, deletedPropertiesByLabel, context, 'Dictionary');
};

const removeDeletedOptionsFromEntities = (current, thesauri) => {
Expand Down

0 comments on commit 43f4660

Please sign in to comment.