Skip to content

Commit

Permalink
fix: functional icon-list
Browse files Browse the repository at this point in the history
  • Loading branch information
Birkbjo committed Mar 20, 2024
1 parent 52aebd9 commit a9a88c5
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 17 deletions.
8 changes: 8 additions & 0 deletions src/List/listValueRenderers.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,11 @@ addValueRenderer(
({ columnName, valueType }) => columnName === 'formType' && valueType === 'CONSTANT',
renderNothingWhenValueIsNotAString(({ value }) => (<Translate>{value.toLowerCase()}</Translate>))
);

addValueRenderer(
({ columnName, valueType, value }) => {
return columnName === 'icon' && valueType === 'URL' && value.endsWith('/icon')
},
({ value }) => <img width={36} src={value} alt={'icon'} />
)

16 changes: 7 additions & 9 deletions src/config/custom-models/icon/IconModelDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,16 @@ export default class IconModelDefinition extends ModelDefinition {
name: iconData.key,
displayName: iconData.key,
id: iconData.key,
user: iconData.createdBy,
icon: iconData.href
});
}
get(id) {
// id is actually key here
console.log('get', id);

return this.api.get(`icons/${id}`).then((icon) => this.iconToModel(icon));
}
return this.api.get(`icons/${id}`).then(icon => this.iconToModel(icon));
}

list() {
console.log('icon list!');
Expand All @@ -94,7 +96,9 @@ export default class IconModelDefinition extends ModelDefinition {
};

const params = {
fields: ':all',
fields:
'key,description,custom,created,lastUpdated,createdBy[id,displayName,name],fileResource,href',
type: 'custom',
search: queryString || '',
};

Expand All @@ -111,12 +115,6 @@ export default class IconModelDefinition extends ModelDefinition {
response.icons,
response.pager
);
console.log({ collection });
// Array.from(collection.valuesContainerMap).forEach(m => {
// m.value.dataValues.id = m.value.key
// m.value.id = m.value.key
// })
// Array.from(collection).map(m => m.id = m.key)
return collection;
});
console.log(res);
Expand Down
92 changes: 86 additions & 6 deletions src/config/custom-models/icon/iconSchemaDefinition.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/* Icon does not have a schema, so we create a synthetic one
It also does not have an id (it has user-defined key instead).
This presents some challenges because a lot of the model-code is tied
to them having an ID. So we add a "synthetic"-ID field
Some other fields are also "synthetic" (eg. does not exist at all on the Icon object)
- Access - this is calculated in the IconModelDefinition
- Name === key
- Displayname === key
- Icon === href . This is mostly because "href"-field is translated to "API URL" by default
- User === createdBy
*/

const iconSchemaDefinition = {
klass: 'org.hisp.dhis.icon',
shareable: false,
Expand All @@ -12,15 +26,15 @@ const iconSchemaDefinition = {
authorities: [
{
type: 'CREATE_PUBLIC',
authorities: ['F_SYSTEM_SETTING', 'F_LOCALE_ADD'],
authorities: ['M_dhis-web-maintenance'],
},
{
type: 'CREATE_PRIVATE',
authorities: ['F_SYSTEM_SETTING', 'F_LOCALE_ADD'],
authorities: ['M_dhis-web-maintenance'],
},
{
type: 'DELETE',
authorities: ['F_SYSTEM_SETTING'],
authorities: ['M_dhis-web-maintenance'],
},
],
properties: [
Expand Down Expand Up @@ -142,10 +156,10 @@ const iconSchemaDefinition = {
propertyTransformer: false,
},
{
klass: 'java.util.List',
klass: 'java.util.Set',
propertyType: 'COLLECTION',
itemKlass: 'org.hisp.dhis.translation.Translation',
itemPropertyType: 'COMPLEX',
itemKlass: 'java.lang.String',
itemPropertyType: 'TEXT',
name: 'keyword',
fieldName: 'keywords',
persisted: false,
Expand Down Expand Up @@ -211,6 +225,38 @@ const iconSchemaDefinition = {
},
propertyTransformer: false,
},
{
klass: 'java.lang.String',
propertyType: 'URL',
name: 'icon',
fieldName: 'href',
persisted: false,
attribute: true,
simple: true,
collection: false,
ordered: false,
owner: false,
identifiableObject: false,
nameableObject: false,
embeddedObject: false,
analyticalObject: false,
readable: true,
writable: true,
unique: false,
required: false,
max: 1.7976931348623157e308,
min: 0,
manyToMany: false,
oneToOne: false,
manyToOne: false,
oneToMany: false,
translatable: false,
gistPreferences: {
included: 'AUTO',
transformation: 'AUTO',
},
propertyTransformer: false,
},
{
fieldName: 'created',
description: 'The date this object was created.',
Expand All @@ -235,6 +281,40 @@ const iconSchemaDefinition = {
persisted: true,
manyToOne: false,
},
{
klass: 'org.hisp.dhis.user.User',
propertyType: 'REFERENCE',
name: 'user',
fieldName: 'user',
persisted: false,
namespace: 'http://dhis2.org/schema/dxf/2.0',
attribute: false,
simple: false,
collection: false,
ordered: false,
owner: false,
identifiableObject: true,
nameableObject: false,
embeddedObject: false,
analyticalObject: false,
readable: true,
writable: true,
unique: false,
required: false,
manyToMany: false,
oneToOne: false,
manyToOne: false,
oneToMany: false,
href: 'https://debug.dhis2.org/dev/api/schemas/user',
relativeApiEndpoint: '/users',
apiEndpoint: 'https://debug.dhis2.org/dev/api/users',
translatable: false,
gistPreferences: {
included: 'AUTO',
transformation: 'AUTO',
},
propertyTransformer: true,
},
{
fieldName: 'lastUpdated',
description: 'The date the object was last updated.',
Expand Down
3 changes: 3 additions & 0 deletions src/config/disabled-on-edit/icon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default [
'key',
];
2 changes: 2 additions & 0 deletions src/config/disabled-on-edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import optionSet from './optionSet';
import programRule from './programRule';
import optionGroup from './optionGroup';
import optionGroupSet from './optionGroupSet';
import icon from './icon.js'

const disabledByType = {
category,
categoryCombo,
categoryOptionCombo,
categoryOptionGroup,
categoryOptionGroupSet,
icon,
optionSet,
programRule,
optionGroup,
Expand Down
6 changes: 6 additions & 0 deletions src/config/field-config/field-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,12 @@ const fieldOrderByName = new Map([
'type',
'sqlQuery',
]],
['icon', [
'key',
'description',
'fileResource',
'keywords',
]],
]);

export default {
Expand Down
3 changes: 1 addition & 2 deletions src/config/maintenance-models.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,8 @@ const typeDetails = {
},
icon: {
columns: [
'displayName',
'key',
'href'
'icon'
],
},
sqlView: {
Expand Down
3 changes: 3 additions & 0 deletions src/i18n/i18n_module_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2186,6 +2186,9 @@ icon_search=Search for icons
upload_icon=Upload icon
choose_file_to_upload=Choose file to upload
icons_custom=Custom
key=Key
keywords=Keywords
icon_management=Icon management

differs_from_program=Differs from program
apply_to_selected_stages=Apply to selected stages
Expand Down

0 comments on commit a9a88c5

Please sign in to comment.