-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add current user filter widget (redo from other branch)
- Loading branch information
Showing
13 changed files
with
587 additions
and
0 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
src/shared/modules/DashboardBuilder/vos/CurrentUserFilterWidgetOptionsVO.ts
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,85 @@ | ||
import DashboardPageWidgetVO from "./DashboardPageWidgetVO"; | ||
import AbstractVO from "../../VO/abstract/AbstractVO"; | ||
import VOFieldRefVO from "./VOFieldRefVO"; | ||
|
||
/** | ||
* CurrentUserFilterWidgetOptionsVO | ||
*/ | ||
export default class CurrentUserFilterWidgetOptionsVO extends AbstractVO { | ||
|
||
public static VO_FIELD_REF_PLACEHOLDER_CODE_PREFIX: string = "CurrentUserFilterWidgetOptions.vo_field_ref.placeholder."; | ||
public static VO_FIELD_REF_ADVANCED_MODE_PLACEHOLDER_CODE_PREFIX: string = "CurrentUserFilterWidgetOptions.vo_field_ref.advanced_mode_placeholder."; | ||
|
||
public static get_selected_fields(page_widget: DashboardPageWidgetVO): { [api_type_id: string]: { [field_id: string]: boolean } } { | ||
let res: { [api_type_id: string]: { [field_id: string]: boolean } } = {}; | ||
|
||
let options: CurrentUserFilterWidgetOptionsVO = (page_widget && page_widget.json_options) ? JSON.parse(page_widget.json_options) : null; | ||
if ((!options) || (!options.vo_field_ref)) { | ||
return res; | ||
} | ||
|
||
if ((!options.vo_field_ref.api_type_id) || (!options.vo_field_ref.field_id)) { | ||
return res; | ||
} | ||
|
||
if (!res[options.vo_field_ref.api_type_id]) { | ||
res[options.vo_field_ref.api_type_id] = {}; | ||
} | ||
|
||
res[options.vo_field_ref.api_type_id][options.vo_field_ref.field_id] = true; | ||
|
||
return res; | ||
} | ||
|
||
public constructor( | ||
public vo_field_ref?: VOFieldRefVO, | ||
public hide_filter?: boolean, | ||
) { | ||
super(); | ||
} | ||
|
||
public get_placeholder_name_code_text(page_widget_id: number): string { | ||
|
||
if ((!this.vo_field_ref) || (!page_widget_id)) { | ||
return null; | ||
} | ||
|
||
return CurrentUserFilterWidgetOptionsVO.VO_FIELD_REF_PLACEHOLDER_CODE_PREFIX + | ||
`${page_widget_id}.` + | ||
`${this.vo_field_ref.api_type_id}.` + | ||
this.vo_field_ref.field_id; | ||
} | ||
|
||
public get_advanced_mode_placeholder_code_text(page_widget_id: number): string { | ||
|
||
if ((!this.vo_field_ref) || (!page_widget_id)) { | ||
return null; | ||
} | ||
|
||
return CurrentUserFilterWidgetOptionsVO.VO_FIELD_REF_ADVANCED_MODE_PLACEHOLDER_CODE_PREFIX + page_widget_id + '.' + this.vo_field_ref.api_type_id + '.' + this.vo_field_ref.field_id; | ||
} | ||
|
||
public async get_all_exportable_name_code_and_translation(page_id: number, page_widget_id: number): Promise<{ [current_code_text: string]: string }> { | ||
let res: { [exportable_code_text: string]: string } = {}; | ||
|
||
let placeholder_name_code_text: string = this.get_placeholder_name_code_text(page_widget_id); | ||
if (placeholder_name_code_text) { | ||
|
||
res[placeholder_name_code_text] = | ||
CurrentUserFilterWidgetOptionsVO.VO_FIELD_REF_PLACEHOLDER_CODE_PREFIX + | ||
'{{IMPORT:' + DashboardPageWidgetVO.API_TYPE_ID + ':' + page_widget_id + '}}' + | ||
'.' + this.vo_field_ref.api_type_id + '.' + this.vo_field_ref.field_id; | ||
} | ||
|
||
let advanced_mode_placeholder_code_text: string = this.get_advanced_mode_placeholder_code_text(page_widget_id); | ||
if (advanced_mode_placeholder_code_text) { | ||
|
||
res[advanced_mode_placeholder_code_text] = | ||
CurrentUserFilterWidgetOptionsVO.VO_FIELD_REF_ADVANCED_MODE_PLACEHOLDER_CODE_PREFIX + | ||
'{{IMPORT:' + DashboardPageWidgetVO.API_TYPE_ID + ':' + page_widget_id + '}}' + | ||
'.' + this.vo_field_ref.api_type_id + '.' + this.vo_field_ref.field_id; | ||
} | ||
return res; | ||
} | ||
|
||
} |
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,11 @@ | ||
import ContextFilterVO from "../../ContextFilter/vos/ContextFilterVO"; | ||
|
||
/** | ||
* FieldFiltersVO | ||
* - Used to describe api_field_filters of dashboard and dashboard_pages | ||
* - api_field_filters is a JSON object of field filters | ||
* - the actual api_type_id key may be a custom api_type_id (e.g. field_filters of dates) | ||
*/ | ||
export default class FieldFiltersVO { | ||
[api_type_id: string]: { [field_id: string]: ContextFilterVO } | ||
} |
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
8 changes: 8 additions & 0 deletions
8
...dashboard_builder/widgets/current_user_filter_widget/CurrentUserFilterWidgetComponent.pug
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,8 @@ | ||
.current_user_filter_widget_component | ||
template(v-if='vo_field_ref') | ||
.vo_field_ref_label {{ vo_field_ref_label }} | ||
.vo_field_ref_value | ||
template(v-if='is_type_string') | ||
input(v-model='current_data_filter.string_value' type='text' disabled='disabled') | ||
template(v-else-if='is_type_number') | ||
input(v-model='current_data_filter.numeric_value' type='text' disabled='disabled') |
2 changes: 2 additions & 0 deletions
2
...ashboard_builder/widgets/current_user_filter_widget/CurrentUserFilterWidgetComponent.scss
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,2 @@ | ||
.current_user_filter_widget_component { | ||
} |
186 changes: 186 additions & 0 deletions
186
.../dashboard_builder/widgets/current_user_filter_widget/CurrentUserFilterWidgetComponent.ts
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,186 @@ | ||
import Component from 'vue-class-component'; | ||
import { Prop, Watch } from 'vue-property-decorator'; | ||
import CurrentUserFilterWidgetOptionsVO from '../../../../../../shared/modules/DashboardBuilder/vos/CurrentUserFilterWidgetOptionsVO'; | ||
import DashboardPageWidgetVO from '../../../../../../shared/modules/DashboardBuilder/vos/DashboardPageWidgetVO'; | ||
import ContextFilterVO from '../../../../../../shared/modules/ContextFilter/vos/ContextFilterVO'; | ||
import VOFieldRefVO from '../../../../../../shared/modules/DashboardBuilder/vos/VOFieldRefVO'; | ||
import UserVO from '../../../../../../shared/modules/AccessPolicy/vos/UserVO'; | ||
import { ModuleTranslatableTextGetter } from '../../../InlineTranslatableText/TranslatableTextStore'; | ||
import { ModuleDashboardPageAction } from '../../page/DashboardPageStore'; | ||
import ConsoleHandler from '../../../../../../shared/tools/ConsoleHandler'; | ||
import VueComponentBase from '../../../VueComponentBase'; | ||
import VOFieldRefVOTypeHandler from '../../../../../../shared/modules/DashboardBuilder/handlers/VOFieldRefVOTypeHandler'; | ||
import ContextFilterVOManager from '../../../../../../shared/modules/ContextFilter/manager/ContextFilterVOManager'; | ||
import VOsTypesManager from '../../../../../../shared/modules/VO/manager/VOsTypesManager'; | ||
import DataFilterOption from '../../../../../../shared/modules/DataRender/vos/DataFilterOption'; | ||
import ModuleTableField from '../../../../../../shared/modules/ModuleTableField'; | ||
import './CurrentUserFilterWidgetComponent.scss'; | ||
|
||
@Component({ | ||
template: require('./CurrentUserFilterWidgetComponent.pug'), | ||
components: {} | ||
}) | ||
export default class CurrentUserFilterWidgetComponent extends VueComponentBase { | ||
|
||
@ModuleDashboardPageAction | ||
private set_active_field_filter: (param: { vo_type: string, field_id: string, active_field_filter: ContextFilterVO }) => void; | ||
|
||
@ModuleTranslatableTextGetter | ||
private get_flat_locale_translations: { [code_text: string]: string }; | ||
|
||
@Prop({ default: null }) | ||
private page_widget: DashboardPageWidgetVO; | ||
|
||
private widget_options: CurrentUserFilterWidgetOptionsVO = null; | ||
|
||
private current_data_filter: DataFilterOption = null; // the current user data filter | ||
private user: UserVO = null; // the current user | ||
|
||
/** | ||
* Watch on page_widget | ||
* | ||
* @returns {void} | ||
*/ | ||
@Watch('page_widget', { immediate: true }) | ||
private onchange_page_widget_options(): void { | ||
this.user = this.data_user; | ||
this.widget_options = this.get_widget_options(); | ||
|
||
this.init_data_filter(); | ||
} | ||
|
||
/** | ||
* Watch on widget_options | ||
* - Shall happen first on component init or each time widget_options changes | ||
* - Initialize the active_field_filter with the context_filter | ||
* | ||
* @returns {void} | ||
*/ | ||
@Watch('widget_options', { immediate: true, deep: true }) | ||
private async onchange_widget_options(): Promise<void> { | ||
|
||
if (!this.widget_options) { | ||
return; | ||
} | ||
|
||
this.init_data_filter(); | ||
} | ||
|
||
/** | ||
* init_data_filter | ||
* - Initialize the active_field_filter with the context_filter | ||
* | ||
* @returns {void} | ||
*/ | ||
private init_data_filter(): void { | ||
|
||
if (!this.widget_options) { | ||
return; | ||
} | ||
|
||
this.current_data_filter = this.create_data_filter(this.vo_field_ref.field_id); | ||
|
||
const context_filter = ContextFilterVOManager.get_context_filter_from_data_filter_option( | ||
this.current_data_filter, | ||
null, | ||
this.field, | ||
this.vo_field_ref | ||
); | ||
|
||
this.set_active_field_filter({ | ||
field_id: this.vo_field_ref.field_id, | ||
vo_type: this.vo_field_ref.api_type_id, | ||
active_field_filter: context_filter, | ||
}); | ||
} | ||
|
||
/** | ||
* get_widget_options | ||
* - Get widget options from page_widget json_options | ||
* | ||
* @returns {CurrentUserFilterWidgetOptionsVO} | ||
*/ | ||
private get_widget_options(): CurrentUserFilterWidgetOptionsVO { | ||
if (!this.page_widget) { | ||
return null; | ||
} | ||
|
||
let options: CurrentUserFilterWidgetOptionsVO = null; | ||
try { | ||
if (this.page_widget.json_options?.length > 0) { | ||
options = JSON.parse(this.page_widget.json_options) as CurrentUserFilterWidgetOptionsVO; | ||
options = options ? new CurrentUserFilterWidgetOptionsVO().from(options) : null; | ||
} | ||
} catch (error) { | ||
ConsoleHandler.error(error); | ||
} | ||
|
||
return options; | ||
} | ||
|
||
/** | ||
* create_data_filter | ||
* - Create a DataFilterOption from a value and a field_id (vo_field_ref) | ||
* | ||
* @param {string} field_id The field_id of the vo_field_ref may be id or name | ||
* @returns {DataFilterOption} | ||
*/ | ||
private create_data_filter(field_id: string): DataFilterOption { | ||
let val: number = this.user[field_id]; // it may be id or login or name | ||
|
||
if (!val) { | ||
return null; | ||
} | ||
|
||
const data_filter = new DataFilterOption( | ||
DataFilterOption.STATE_SELECTED, | ||
this.t(this.field?.field_label ?? field_id), | ||
val | ||
); | ||
|
||
if (this.is_type_string) { | ||
data_filter.string_value = val.toString(); | ||
} | ||
|
||
if (this.is_type_number) { | ||
data_filter.numeric_value = val; | ||
} | ||
|
||
return data_filter; | ||
} | ||
|
||
get vo_field_ref(): VOFieldRefVO { | ||
let options: CurrentUserFilterWidgetOptionsVO = this.widget_options; | ||
|
||
if ((!options) || (!options.vo_field_ref)) { | ||
return null; | ||
} | ||
|
||
return new VOFieldRefVO().from(options.vo_field_ref); | ||
} | ||
|
||
get field(): ModuleTableField<any> { | ||
if (!this.vo_field_ref) { | ||
return null; | ||
} | ||
|
||
const moduletable = VOsTypesManager.moduleTables_by_voType[this.vo_field_ref.api_type_id]; | ||
return moduletable.get_field_by_id(this.vo_field_ref.field_id); | ||
} | ||
|
||
get vo_field_ref_label(): string { | ||
if ((!this.widget_options) || (!this.vo_field_ref)) { | ||
return null; | ||
} | ||
|
||
return this.get_flat_locale_translations[this.vo_field_ref.get_translatable_name_code_text(this.page_widget.id)]; | ||
} | ||
|
||
get is_type_string(): boolean { | ||
return VOFieldRefVOTypeHandler.is_type_string(this.vo_field_ref); | ||
} | ||
|
||
get is_type_number(): boolean { | ||
return VOFieldRefVOTypeHandler.is_type_number(this.vo_field_ref); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
..._builder/widgets/current_user_filter_widget/icon/CurrentUserFilterWidgetIconComponent.pug
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,6 @@ | ||
.current_user_filter_widget_icon | ||
template(v-if='!widget') | ||
template(v-else) | ||
.fa-stack.fa-lg.fa-fw(aria-hidden='true') | ||
i.fa-solid.fa-user.fa-stack-2x | ||
i.fa-solid.fa-bullseye.fa-stack-1x |
14 changes: 14 additions & 0 deletions
14
...builder/widgets/current_user_filter_widget/icon/CurrentUserFilterWidgetIconComponent.scss
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 @@ | ||
.current_user_filter_widget_icon { | ||
i.fa-solid.fa-bullseye.fa-stack-1x { | ||
position: absolute; | ||
left: 0px; | ||
bottom: 0px; | ||
width: auto; | ||
height: auto; | ||
color: dodgerblue; | ||
background: transparent; | ||
padding: 1px 3px; | ||
margin: 0; | ||
line-height: 1.1em; | ||
} | ||
} |
Oops, something went wrong.