-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1231 - moved code from UI, service, and reducer to model objects. us…
…e voiding to for card mapping and section instead of remove. use card mapping to keep display order. removed some stories.
- Loading branch information
1 parent
bbd85cf
commit ca1455e
Showing
15 changed files
with
228 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import _ from "lodash"; | ||
import WebDashboardSection from "./WebDashboardSection"; | ||
|
||
class WebDashboard { | ||
static createNew() { | ||
return { name: "", description: "", sections: [], filters: [] }; | ||
} | ||
|
||
static removeSection(dashboard, section) { | ||
const dashboardSection = _.find(dashboard.sections, x => x.uuid === section.uuid); | ||
dashboardSection.voided = true; | ||
dashboard.sections = [...dashboard.sections]; | ||
return { ...dashboard }; | ||
} | ||
|
||
static updateSection(dashboard, section) { | ||
const index = _.findIndex(dashboard.sections, x => x.uuid === section.uuid); | ||
dashboard.sections[index] = section; | ||
return { ...dashboard }; | ||
} | ||
|
||
static reOrderSections(dashboard, sourceIndex, destIndex) { | ||
const result = [...dashboard.sections]; | ||
const [removed] = result.splice(sourceIndex, 1); | ||
result.splice(destIndex, 0, removed); | ||
dashboard.sections = result; | ||
return { ...dashboard }; | ||
} | ||
|
||
static addNewSection(dashboard) { | ||
dashboard.sections.push(WebDashboardSection.newSection()); | ||
dashboard.sections = _.sortBy(dashboard.sections, "displayOrder"); | ||
return { ...dashboard }; | ||
} | ||
|
||
static toResource(dashboard) { | ||
const resource = { | ||
uuid: dashboard.uuid, | ||
id: dashboard.id, | ||
name: dashboard.name, | ||
description: dashboard.description | ||
}; | ||
resource.sections = WebDashboardSection.toResources(dashboard.sections); | ||
resource.filters = dashboard.filters.map(x => { | ||
return { | ||
name: x.name, | ||
voided: x.voided, | ||
uuid: x.uuid, | ||
filterConfig: x.filterConfig.toServerRequest() | ||
}; | ||
}); | ||
return resource; | ||
} | ||
} | ||
|
||
export default WebDashboard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { ModelGeneral as General } from "openchs-models"; | ||
import _ from "lodash"; | ||
import WebDashboardSectionCardMapping from "./WebDashboardSectionCardMapping"; | ||
|
||
class WebDashboardSection { | ||
dashboardSectionCardMappings; | ||
|
||
static getReportCards(section) { | ||
return section.dashboardSectionCardMappings.filter(x => !x.voided).map(x => x.card); | ||
} | ||
|
||
static newSection() { | ||
return { | ||
name: "", | ||
description: "", | ||
viewType: "", | ||
displayOrder: 100, | ||
dashboardSectionCardMappings: [], | ||
uuid: General.randomUUID(), | ||
voided: false | ||
}; | ||
} | ||
|
||
static removeCard(section, card) { | ||
const mapping = _.find(section.dashboardSectionCardMappings, x => x.card.uuid === card.uuid); | ||
mapping.voided = true; | ||
section.dashboardSectionCardMappings = [...section.dashboardSectionCardMappings]; | ||
return { ...section }; | ||
} | ||
|
||
static reorderCards(section, startIndex, endIndex) { | ||
const result = [...section.dashboardSectionCardMappings]; | ||
const [removed] = result.splice(startIndex, 1); | ||
result.splice(endIndex, 0, removed); | ||
section.dashboardSectionCardMappings = result; | ||
return { ...section }; | ||
} | ||
|
||
static addCards(section, cards) { | ||
//get max display order | ||
let nextDisplayOrder = | ||
_.reduce( | ||
section.dashboardSectionCardMappings, | ||
(max, dashboardSectionCardMapping) => { | ||
return dashboardSectionCardMapping.displayOrder > max ? dashboardSectionCardMapping.displayOrder : max; | ||
}, | ||
0 | ||
) + 1; | ||
|
||
cards.forEach(card => { | ||
section.dashboardSectionCardMappings.push({ | ||
card: card, | ||
displayOrder: nextDisplayOrder | ||
}); | ||
nextDisplayOrder++; | ||
}); | ||
|
||
section.dashboardSectionCardMappings = [...section.dashboardSectionCardMappings]; | ||
return { ...section }; | ||
} | ||
|
||
static getCardsNotAdded(section, allCards) { | ||
const cardsAdded = WebDashboardSection.getReportCards(section); | ||
return _.differenceBy(allCards, cardsAdded, "uuid"); | ||
} | ||
|
||
static toResources(sections) { | ||
return sections.map(section => { | ||
return { | ||
name: section.name, | ||
description: section.description, | ||
viewType: section.viewType, | ||
displayOrder: section.displayOrder, | ||
uuid: section.uuid, | ||
voided: section.voided, | ||
dashboardSectionCardMappings: WebDashboardSectionCardMapping.toResources(section.dashboardSectionCardMappings) | ||
}; | ||
}); | ||
} | ||
} | ||
|
||
export default WebDashboardSection; |
14 changes: 14 additions & 0 deletions
14
src/common/model/reports/WebDashboardSectionCardMapping.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class WebDashboardSectionCardMapping { | ||
static toResources(dashboardSectionCardMappings) { | ||
return dashboardSectionCardMappings.map(dashboardSectionCardMapping => { | ||
return { | ||
reportCardUUID: dashboardSectionCardMapping.card.uuid, | ||
displayOrder: dashboardSectionCardMapping.displayOrder, | ||
uuid: dashboardSectionCardMapping.uuid, | ||
voided: dashboardSectionCardMapping.voided | ||
}; | ||
}); | ||
} | ||
} | ||
|
||
export default WebDashboardSectionCardMapping; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.