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

Added a new datatype named as "profile photo" as field type in Admin UI. #2546

Merged
merged 26 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
85ea594
Added a new datatype named as "profile photo" as field type in Admin UI.
sadaf895 Aug 28, 2024
b497dda
Merge branch 'master' into Setup_Wizard
sleidig Aug 29, 2024
44efc0b
1)Change the datatype of "photo" attribute.
sadaf895 Aug 30, 2024
66f4df1
Merge branch 'Setup_Wizard' of https://github.com/Aam-Digital/ndb-cor…
sadaf895 Aug 30, 2024
036c8f5
Update src/app/core/config/config.service.ts
sadaf895 Sep 2, 2024
ec401b7
Update src/app/core/config/config.service.spec.ts
sadaf895 Sep 2, 2024
36f5a26
Update src/app/core/config/config.service.spec.ts
sadaf895 Sep 2, 2024
e377a3c
Update src/app/core/config/config.service.spec.ts
sadaf895 Sep 2, 2024
974ed64
Update src/app/core/config/config-fix.ts
sadaf895 Sep 2, 2024
2910b13
extend unit test for config migration
sleidig Sep 2, 2024
75da308
Created a new datatype"percentage"
sadaf895 Sep 2, 2024
5179054
Merge branch 'Setup_Wizard' of https://github.com/Aam-Digital/ndb-cor…
sadaf895 Sep 2, 2024
c434b56
Update src/app/core/basic-datatypes/number/display-percentage/percent…
sadaf895 Sep 4, 2024
adcb701
Updated the migration code for "photo" datatype
sadaf895 Sep 4, 2024
940a043
written test and migration code for percentage datatype.
sadaf895 Sep 4, 2024
5526d9b
Merge branch 'master' into Setup_Wizard
sleidig Sep 4, 2024
ec6f3bd
Update src/app/core/config/config-fix.ts
sadaf895 Sep 4, 2024
e711bfd
Update src/app/core/config/config-fix.ts
sadaf895 Sep 4, 2024
9cbeb48
Update src/app/core/config/config.service.spec.ts
sadaf895 Sep 4, 2024
54cc009
Clean uo code for final review
sadaf895 Sep 4, 2024
c4b6cd2
Update src/app/features/file/photo.datatype.ts
sleidig Sep 4, 2024
8703fa8
Update src/app/core/config/config.service.ts
sleidig Sep 4, 2024
a89fe6d
remove unneccessary package
sadaf895 Sep 4, 2024
7797b69
Merge branch 'Setup_Wizard' of https://github.com/Aam-Digital/ndb-cor…
sadaf895 Sep 4, 2024
be84e12
fix: change chromium version to 120.0.6099.224-1~deb11u1
tomwwinter Sep 4, 2024
3554b32
fix: change chromium version to 128.0.6613.113-1~deb12u1
tomwwinter Sep 4, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Injectable } from "@angular/core";
import { NumberDatatype } from "../number.datatype";

/** Datatype for percentage values */
@Injectable()
export class PercentageDatatype extends NumberDatatype {
static override dataType = "percentage";
static override label: string = $localize`:datatype-label:Percentage`;

override viewComponent = "DisplayPercentage";
override editComponent = "EditNumber";
}
7 changes: 2 additions & 5 deletions src/app/core/config/config-fix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1018,9 +1018,8 @@ export const defaultJsonConfig = {
label: $localize`:Label for the remarks about a dropout of a child:Dropout remarks`,
},
photo: {
dataType: "file",
dataType: "photo",
label: $localize`:Label for the file field of a photo of a child:Photo`,
editComponent: "EditPhoto",
},
phone: {
dataType: "string",
Expand Down Expand Up @@ -1301,10 +1300,8 @@ export const defaultJsonConfig = {
anonymize: "retain",
},
result: {
dataType: "number",
dataType: "percentage",
label: $localize`:Label for the percentage result of a relation:Result`,
viewComponent: "DisplayPercentage",
editComponent: "EditNumber",
validators: {
min: 0,
max: 100,
Expand Down
86 changes: 86 additions & 0 deletions src/app/core/config/config.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { UpdatedEntity } from "../entity/model/entity-update";
import { EntityConfig } from "../entity/entity-config";
import { FieldGroup } from "../entity-details/form/field-group";
import { NavigationMenuConfig } from "../ui/navigation/menu-item";
import { result } from "lodash-es";
sleidig marked this conversation as resolved.
Show resolved Hide resolved

describe("ConfigService", () => {
let service: ConfigService;
Expand Down Expand Up @@ -550,4 +551,89 @@ describe("ConfigService", () => {
const actualFromNew = service.getConfig("view:X");
expect(actualFromNew).toEqual(newFormat);
}));

it("should migrate to new photo dataType", fakeAsync(() => {
const config = new Config();
const oldFormat = {
attributes: {
myPhoto: {
dataType: "file",
editComponent: "EditPhoto",
label: "My Photo",
},
simpleFile: {
dataType: "file",
label: "Simple File attachment",
},
},
};

const newFormat: EntityConfig = {
attributes: {
myPhoto: {
dataType: "photo",
label: "My Photo",
},
simpleFile: {
dataType: "file",
label: "Simple File attachment",
},
},
};

config.data = { "entity:X": oldFormat };
updateSubject.next({ entity: config, type: "update" });
tick();
const actualFromOld = service.getConfig<EntityConfig>("entity:X");
expect(actualFromOld).toEqual(newFormat);

config.data = { "entity:X": newFormat };
updateSubject.next({ entity: config, type: "update" });
tick();
const actualFromNew = service.getConfig<EntityConfig>("entity:X");
expect(actualFromNew).toEqual(newFormat);
}));

it("should migrate to Percentage dataType", fakeAsync(() => {
const config = new Config();
const oldFormat = {
attributes: {
myPercentage: {
dataType: "number",
viewComponent: "DisplayPercentage",
editComponent: "EditNumber",
label: "My Percentage",
},
simpleNumber: {
dataType: "number",
label: "Simple Number",
},
},
};

const newFormat: EntityConfig = {
attributes: {
myPercentage: {
dataType: "percentage",
label: "My Percentage",
},
simpleNumber: {
dataType: "number",
label: "Simple Number",
},
},
};

config.data = { "entity:X": oldFormat };
updateSubject.next({ entity: config, type: "update" });
tick();
const actualFromOld = service.getConfig<EntityConfig>("entity:X");
expect(actualFromOld).toEqual(newFormat);

config.data = { "entity:X": newFormat };
updateSubject.next({ entity: config, type: "update" });
tick();
const actualFromNew = service.getConfig<EntityConfig>("entity:X");
expect(actualFromNew).toEqual(newFormat);
}));
});
29 changes: 29 additions & 0 deletions src/app/core/config/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export class ConfigService extends LatestEntityLoader<Config> {
migrateEntitySchemaDefaultValue,
migrateChildrenListConfig,
migrateHistoricalDataComponent,
migratePhotoDatatype,
migratePercentageDatatype,
];

// TODO: execute this on server via ndb-admin
Expand Down Expand Up @@ -259,6 +261,33 @@ const migrateEntityArrayDatatype: ConfigMigration = (key, configPart) => {
return configPart;
};

/** Migrate the "file" datatype to use the new "photo" datatype and remove editComponent if no longer needed */

sleidig marked this conversation as resolved.
Show resolved Hide resolved
const migratePhotoDatatype: ConfigMigration = (key, configPart) => {
if (
configPart?.dataType === "file" &&
configPart?.editComponent === "EditPhoto"
) {
configPart.dataType = "photo";
delete configPart.editComponent;
}
return configPart;
};

/** Migrate the number datatype to use the new "percentage" datatype */
const migratePercentageDatatype: ConfigMigration = (key, configPart) => {
if (
configPart?.dataType === "number" &&
configPart?.viewComponent === "DisplayPercentage"
) {
configPart.dataType = "percentage";
delete configPart.viewComponent;
delete configPart.editComponent;
}

return configPart;
};

const migrateEntitySchemaDefaultValue: ConfigMigration = (
key: string,
configPart: any,
Expand Down
2 changes: 2 additions & 0 deletions src/app/core/core.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { LongTextDatatype } from "./basic-datatypes/string/long-text.datatype";
import { UpdateMetadataDatatype } from "./entity/model/update-metadata.datatype";
import { CurrentUserSubject } from "./session/current-user-subject";
import { SessionSubject } from "./session/auth/session-info";
import { PercentageDatatype } from "./basic-datatypes/number/display-percentage/percentage.datatype";

/**
* Core module registering basic parts like datatypes and components.
Expand All @@ -37,6 +38,7 @@ import { SessionSubject } from "./session/auth/session-info";
{ provide: DefaultDatatype, useClass: MonthDatatype, multi: true },
{ provide: DefaultDatatype, useClass: DateDatatype, multi: true },
{ provide: DefaultDatatype, useClass: EntityDatatype, multi: true },
{ provide: DefaultDatatype, useClass: PercentageDatatype, multi: true },
],
imports: [CommonModule],
})
Expand Down
2 changes: 2 additions & 0 deletions src/app/features/file/file.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ComponentRegistry } from "../../dynamic-components";
import { fileComponents } from "./file-components";
import { DefaultDatatype } from "../../core/entity/default-datatype/default.datatype";
import { FileDatatype } from "./file.datatype";
import { PhotoDatatype } from "./photo.datatype";

@NgModule({
providers: [
Expand All @@ -20,6 +21,7 @@ import { FileDatatype } from "./file.datatype";
: injector.get(MockFileService);
}),
{ provide: DefaultDatatype, useClass: FileDatatype, multi: true },
{ provide: DefaultDatatype, useClass: PhotoDatatype, multi: true },
sleidig marked this conversation as resolved.
Show resolved Hide resolved
],
})
export class FileModule {
Expand Down
12 changes: 12 additions & 0 deletions src/app/features/file/photo.datatype.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Injectable } from "@angular/core";
import { FileDatatype } from "./file.datatype";

/** Datatype for saving a photo on an entity property.*/

sleidig marked this conversation as resolved.
Show resolved Hide resolved
@Injectable()
export class PhotoDatatype extends FileDatatype {
static override dataType = "photo";
static override label: string = $localize`:datatype-label:profile photo`;

override editComponent = "EditPhoto";
}
Loading