aboutsummaryrefslogtreecommitdiff
path: root/src/client/northstar/core/attribute/CalculatedAttributeModel.ts
diff options
context:
space:
mode:
authorTyler Schicke <tyler_schicke@brown.edu>2019-03-21 21:36:52 -0400
committerTyler Schicke <tyler_schicke@brown.edu>2019-03-21 21:36:52 -0400
commitce4e7a03e82c71bd5c979b19308f4dba03be08a2 (patch)
tree3f1eb320790bd66cc128c8899c5ee9ed170d3382 /src/client/northstar/core/attribute/CalculatedAttributeModel.ts
parent27299e9666ec0aae6a4d1335fd30b2714ad67970 (diff)
parent1cf618563838f4ce7d8a98c8a0c8d94670bc4e18 (diff)
Merge branch 'master' of github-tsch-brown:browngraphicslab/Dash-Web into promises_and_user_document
Diffstat (limited to 'src/client/northstar/core/attribute/CalculatedAttributeModel.ts')
-rw-r--r--src/client/northstar/core/attribute/CalculatedAttributeModel.ts42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/client/northstar/core/attribute/CalculatedAttributeModel.ts b/src/client/northstar/core/attribute/CalculatedAttributeModel.ts
new file mode 100644
index 000000000..ab96c794d
--- /dev/null
+++ b/src/client/northstar/core/attribute/CalculatedAttributeModel.ts
@@ -0,0 +1,42 @@
+import { BackendAttributeModel, AttributeModel, CodeAttributeModel } from "./AttributeModel";
+import { DataType, VisualizationHint } from '../../model/idea/idea'
+
+export class CalculatedAttributeManager {
+ public static AllCalculatedAttributes: Array<AttributeModel> = new Array<AttributeModel>();
+
+ public static Clear() {
+ this.AllCalculatedAttributes = new Array<AttributeModel>();
+ }
+
+ public static CreateBackendAttributeModel(id: string, dataType: DataType, displayName: string, codeName: string, visualizationHints: VisualizationHint[]): BackendAttributeModel {
+ var filtered = this.AllCalculatedAttributes.filter(am => {
+ if (am instanceof BackendAttributeModel &&
+ am.Id == id) {
+ return true;
+ }
+ return false;
+ });
+ if (filtered.length > 0) {
+ return filtered[0] as BackendAttributeModel;
+ }
+ var newAttr = new BackendAttributeModel(id, dataType, displayName, codeName, visualizationHints);
+ this.AllCalculatedAttributes.push(newAttr);
+ return newAttr;
+ }
+
+ public static CreateCodeAttributeModel(code: string, codeName: string, visualizationHints: VisualizationHint[]): CodeAttributeModel {
+ var filtered = this.AllCalculatedAttributes.filter(am => {
+ if (am instanceof CodeAttributeModel &&
+ am.CodeName == codeName) {
+ return true;
+ }
+ return false;
+ });
+ if (filtered.length > 0) {
+ return filtered[0] as CodeAttributeModel;
+ }
+ var newAttr = new CodeAttributeModel(code, codeName, codeName.ReplaceAll("_", " "), visualizationHints);
+ this.AllCalculatedAttributes.push(newAttr);
+ return newAttr;
+ }
+} \ No newline at end of file