@memberjunction/ng-entity-permissions 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,16 @@
1
+ import { EventEmitter, OnInit } from '@angular/core';
2
+ import { EntityInfo } from '@memberjunction/core';
3
+ import { EntityPermissionChangedEvent } from '../grid/entity-permissions-grid.component';
4
+ import * as i0 from "@angular/core";
5
+ export declare class EntityPermissionsSelectorWithGridComponent implements OnInit {
6
+ EntityName: string;
7
+ BottomMargin: number;
8
+ PermissionChanged: EventEmitter<EntityPermissionChangedEvent>;
9
+ CurrentEntity: EntityInfo | undefined;
10
+ private _md;
11
+ entityList: EntityInfo[];
12
+ ngOnInit(): void;
13
+ handlePermissionChanged(event: EntityPermissionChangedEvent): void;
14
+ static ɵfac: i0.ɵɵFactoryDeclaration<EntityPermissionsSelectorWithGridComponent, never>;
15
+ static ɵcmp: i0.ɵɵComponentDeclaration<EntityPermissionsSelectorWithGridComponent, "mj-entity-permissions-selector-with-grid", never, { "EntityName": { "alias": "EntityName"; "required": false; }; "BottomMargin": { "alias": "BottomMargin"; "required": false; }; "CurrentEntity": { "alias": "CurrentEntity"; "required": false; }; }, { "PermissionChanged": "PermissionChanged"; }, never, never, false, never>;
16
+ }
@@ -0,0 +1,61 @@
1
+ import { Component, Output, EventEmitter, Input } from '@angular/core';
2
+ import { Metadata } from '@memberjunction/core';
3
+ import * as i0 from "@angular/core";
4
+ import * as i1 from "@angular/common";
5
+ import * as i2 from "@memberjunction/ng-container-directives";
6
+ import * as i3 from "@progress/kendo-angular-dropdowns";
7
+ import * as i4 from "../grid/entity-permissions-grid.component";
8
+ function EntityPermissionsSelectorWithGridComponent_mj_entity_permissions_grid_2_Template(rf, ctx) { if (rf & 1) {
9
+ const _r2 = i0.ɵɵgetCurrentView();
10
+ i0.ɵɵelementStart(0, "mj-entity-permissions-grid", 3);
11
+ i0.ɵɵlistener("PermissionChanged", function EntityPermissionsSelectorWithGridComponent_mj_entity_permissions_grid_2_Template_mj_entity_permissions_grid_PermissionChanged_0_listener($event) { i0.ɵɵrestoreView(_r2); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.handlePermissionChanged($event)); });
12
+ i0.ɵɵelementEnd();
13
+ } if (rf & 2) {
14
+ const ctx_r0 = i0.ɵɵnextContext();
15
+ i0.ɵɵproperty("EntityName", ctx_r0.CurrentEntity.Name);
16
+ } }
17
+ export class EntityPermissionsSelectorWithGridComponent {
18
+ constructor() {
19
+ this.BottomMargin = 0;
20
+ this.PermissionChanged = new EventEmitter();
21
+ this.entityList = [];
22
+ }
23
+ ngOnInit() {
24
+ var _a;
25
+ this._md = new Metadata();
26
+ this.entityList = this._md.Entities.sort((a, b) => a.Name.localeCompare(b.Name));
27
+ if (((_a = this.entityList) === null || _a === void 0 ? void 0 : _a.length) > 0)
28
+ this.CurrentEntity = this.entityList[0];
29
+ }
30
+ handlePermissionChanged(event) {
31
+ // bubble up the event to our container component
32
+ this.PermissionChanged.emit(event);
33
+ }
34
+ }
35
+ EntityPermissionsSelectorWithGridComponent.ɵfac = function EntityPermissionsSelectorWithGridComponent_Factory(t) { return new (t || EntityPermissionsSelectorWithGridComponent)(); };
36
+ EntityPermissionsSelectorWithGridComponent.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: EntityPermissionsSelectorWithGridComponent, selectors: [["mj-entity-permissions-selector-with-grid"]], inputs: { EntityName: "EntityName", BottomMargin: "BottomMargin", CurrentEntity: "CurrentEntity" }, outputs: { PermissionChanged: "PermissionChanged" }, decls: 3, vars: 3, consts: [["mjFillContainer", ""], ["textField", "Name", "valueField", "Name", "placeholder", "Select an entity...", 1, "entity-selector", 3, "data", "value", "valueChange"], ["class", "inner-grid", 3, "EntityName", "PermissionChanged", 4, "ngIf"], [1, "inner-grid", 3, "EntityName", "PermissionChanged"]], template: function EntityPermissionsSelectorWithGridComponent_Template(rf, ctx) { if (rf & 1) {
37
+ i0.ɵɵelementStart(0, "div", 0)(1, "kendo-dropdownlist", 1);
38
+ i0.ɵɵtwoWayListener("valueChange", function EntityPermissionsSelectorWithGridComponent_Template_kendo_dropdownlist_valueChange_1_listener($event) { i0.ɵɵtwoWayBindingSet(ctx.CurrentEntity, $event) || (ctx.CurrentEntity = $event); return $event; });
39
+ i0.ɵɵelementEnd();
40
+ i0.ɵɵtemplate(2, EntityPermissionsSelectorWithGridComponent_mj_entity_permissions_grid_2_Template, 1, 1, "mj-entity-permissions-grid", 2);
41
+ i0.ɵɵelementEnd();
42
+ } if (rf & 2) {
43
+ i0.ɵɵadvance();
44
+ i0.ɵɵproperty("data", ctx.entityList);
45
+ i0.ɵɵtwoWayProperty("value", ctx.CurrentEntity);
46
+ i0.ɵɵadvance();
47
+ i0.ɵɵproperty("ngIf", ctx.CurrentEntity);
48
+ } }, dependencies: [i1.NgIf, i2.FillContainer, i3.DropDownListComponent, i4.EntityPermissionsGridComponent], styles: [".entity-selector[_ngcontent-%COMP%] {\r\n min-width: 200px;\r\n max-width: 500px;\r\n}"] });
49
+ (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(EntityPermissionsSelectorWithGridComponent, [{
50
+ type: Component,
51
+ args: [{ selector: 'mj-entity-permissions-selector-with-grid', template: "<div mjFillContainer>\r\n <kendo-dropdownlist\r\n [data]=\"entityList\"\r\n textField=\"Name\"\r\n valueField=\"Name\"\r\n placeholder=\"Select an entity...\"\r\n class=\"entity-selector\"\r\n [(value)]=\"CurrentEntity\"\r\n >\r\n </kendo-dropdownlist>\r\n <mj-entity-permissions-grid class=\"inner-grid\" *ngIf=\"CurrentEntity\" [EntityName]=\"CurrentEntity.Name\" (PermissionChanged)=\"handlePermissionChanged($event)\"></mj-entity-permissions-grid>\r\n</div>\r\n ", styles: [".entity-selector {\r\n min-width: 200px;\r\n max-width: 500px;\r\n}"] }]
52
+ }], null, { EntityName: [{
53
+ type: Input
54
+ }], BottomMargin: [{
55
+ type: Input
56
+ }], PermissionChanged: [{
57
+ type: Output
58
+ }], CurrentEntity: [{
59
+ type: Input
60
+ }] }); })();
61
+ (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(EntityPermissionsSelectorWithGridComponent, { className: "EntityPermissionsSelectorWithGridComponent", filePath: "src\\lib\\entity-selector-with-grid\\entity-selector-with-grid.component.ts", lineNumber: 13 }); })();
@@ -0,0 +1,30 @@
1
+ import { EventEmitter, OnInit, SimpleChanges, OnChanges } from '@angular/core';
2
+ import { kendoSVGIcon } from '@memberjunction/ng-shared';
3
+ import { EntityPermissionEntity } from '@memberjunction/core-entities';
4
+ import * as i0 from "@angular/core";
5
+ export type EntityPermissionChangedEvent = {
6
+ EntityName: string;
7
+ RoleName: string;
8
+ PermissionTypeChanged: 'Read' | 'Create' | 'Update' | 'Delete';
9
+ Value: boolean;
10
+ Cancel: boolean;
11
+ };
12
+ export declare class EntityPermissionsGridComponent implements OnInit, OnChanges {
13
+ EntityName: string;
14
+ BottomMargin: number;
15
+ PermissionChanged: EventEmitter<EntityPermissionChangedEvent>;
16
+ permissions: EntityPermissionEntity[];
17
+ gridHeight: number;
18
+ isLoading: boolean;
19
+ kendoSVGIcon: typeof kendoSVGIcon;
20
+ constructor();
21
+ ngOnInit(): void;
22
+ ngOnChanges(changes: SimpleChanges): void;
23
+ Refresh(): Promise<void>;
24
+ savePermissions(): Promise<void>;
25
+ get NumDirtyPermissions(): number;
26
+ protected IsPermissionReallyDirty(p: EntityPermissionEntity): boolean;
27
+ flipPermission(event: MouseEvent, permission: EntityPermissionEntity, type: 'Read' | 'Create' | 'Update' | 'Delete', flipPermission: boolean): void;
28
+ static ɵfac: i0.ɵɵFactoryDeclaration<EntityPermissionsGridComponent, never>;
29
+ static ɵcmp: i0.ɵɵComponentDeclaration<EntityPermissionsGridComponent, "mj-entity-permissions-grid", never, { "EntityName": { "alias": "EntityName"; "required": false; }; "BottomMargin": { "alias": "BottomMargin"; "required": false; }; }, { "PermissionChanged": "PermissionChanged"; }, never, never, false, never>;
30
+ }
@@ -0,0 +1,239 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { Component, Output, EventEmitter, Input } from '@angular/core';
11
+ import { Metadata, RunView } from '@memberjunction/core';
12
+ import { kendoSVGIcon } from '@memberjunction/ng-shared';
13
+ import * as i0 from "@angular/core";
14
+ import * as i1 from "@angular/common";
15
+ import * as i2 from "@angular/forms";
16
+ import * as i3 from "@memberjunction/ng-container-directives";
17
+ import * as i4 from "@progress/kendo-angular-buttons";
18
+ function EntityPermissionsGridComponent_div_1_Template(rf, ctx) { if (rf & 1) {
19
+ i0.ɵɵelementStart(0, "div");
20
+ i0.ɵɵtext(1, "Loading permissions...");
21
+ i0.ɵɵelementEnd();
22
+ } }
23
+ function EntityPermissionsGridComponent_button_2_Template(rf, ctx) { if (rf & 1) {
24
+ const _r4 = i0.ɵɵgetCurrentView();
25
+ i0.ɵɵelementStart(0, "button", 4);
26
+ i0.ɵɵlistener("click", function EntityPermissionsGridComponent_button_2_Template_button_click_0_listener() { i0.ɵɵrestoreView(_r4); const ctx_r3 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r3.savePermissions()); });
27
+ i0.ɵɵtext(1, "Save");
28
+ i0.ɵɵelementEnd();
29
+ } }
30
+ function EntityPermissionsGridComponent_table_3_tr_14_Template(rf, ctx) { if (rf & 1) {
31
+ const _r8 = i0.ɵɵgetCurrentView();
32
+ i0.ɵɵelementStart(0, "tr")(1, "td");
33
+ i0.ɵɵtext(2);
34
+ i0.ɵɵelementEnd();
35
+ i0.ɵɵelementStart(3, "td", 7);
36
+ i0.ɵɵlistener("click", function EntityPermissionsGridComponent_table_3_tr_14_Template_td_click_3_listener($event) { const restoredCtx = i0.ɵɵrestoreView(_r8); const permission_r6 = restoredCtx.$implicit; const ctx_r7 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r7.flipPermission($event, permission_r6, "Read", true)); });
37
+ i0.ɵɵelementStart(4, "input", 8);
38
+ i0.ɵɵtwoWayListener("ngModelChange", function EntityPermissionsGridComponent_table_3_tr_14_Template_input_ngModelChange_4_listener($event) { const restoredCtx = i0.ɵɵrestoreView(_r8); const permission_r6 = restoredCtx.$implicit; i0.ɵɵtwoWayBindingSet(permission_r6.CanRead, $event) || (permission_r6.CanRead = $event); return i0.ɵɵresetView($event); });
39
+ i0.ɵɵlistener("click", function EntityPermissionsGridComponent_table_3_tr_14_Template_input_click_4_listener($event) { const restoredCtx = i0.ɵɵrestoreView(_r8); const permission_r6 = restoredCtx.$implicit; const ctx_r10 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r10.flipPermission($event, permission_r6, "Read", false)); });
40
+ i0.ɵɵelementEnd()();
41
+ i0.ɵɵelementStart(5, "td", 7);
42
+ i0.ɵɵlistener("click", function EntityPermissionsGridComponent_table_3_tr_14_Template_td_click_5_listener($event) { const restoredCtx = i0.ɵɵrestoreView(_r8); const permission_r6 = restoredCtx.$implicit; const ctx_r11 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r11.flipPermission($event, permission_r6, "Update", true)); });
43
+ i0.ɵɵelementStart(6, "input", 8);
44
+ i0.ɵɵtwoWayListener("ngModelChange", function EntityPermissionsGridComponent_table_3_tr_14_Template_input_ngModelChange_6_listener($event) { const restoredCtx = i0.ɵɵrestoreView(_r8); const permission_r6 = restoredCtx.$implicit; i0.ɵɵtwoWayBindingSet(permission_r6.CanUpdate, $event) || (permission_r6.CanUpdate = $event); return i0.ɵɵresetView($event); });
45
+ i0.ɵɵlistener("click", function EntityPermissionsGridComponent_table_3_tr_14_Template_input_click_6_listener($event) { const restoredCtx = i0.ɵɵrestoreView(_r8); const permission_r6 = restoredCtx.$implicit; const ctx_r13 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r13.flipPermission($event, permission_r6, "Update", false)); });
46
+ i0.ɵɵelementEnd()();
47
+ i0.ɵɵelementStart(7, "td", 7);
48
+ i0.ɵɵlistener("click", function EntityPermissionsGridComponent_table_3_tr_14_Template_td_click_7_listener($event) { const restoredCtx = i0.ɵɵrestoreView(_r8); const permission_r6 = restoredCtx.$implicit; const ctx_r14 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r14.flipPermission($event, permission_r6, "Create", true)); });
49
+ i0.ɵɵelementStart(8, "input", 8);
50
+ i0.ɵɵtwoWayListener("ngModelChange", function EntityPermissionsGridComponent_table_3_tr_14_Template_input_ngModelChange_8_listener($event) { const restoredCtx = i0.ɵɵrestoreView(_r8); const permission_r6 = restoredCtx.$implicit; i0.ɵɵtwoWayBindingSet(permission_r6.CanCreate, $event) || (permission_r6.CanCreate = $event); return i0.ɵɵresetView($event); });
51
+ i0.ɵɵlistener("click", function EntityPermissionsGridComponent_table_3_tr_14_Template_input_click_8_listener($event) { const restoredCtx = i0.ɵɵrestoreView(_r8); const permission_r6 = restoredCtx.$implicit; const ctx_r16 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r16.flipPermission($event, permission_r6, "Create", false)); });
52
+ i0.ɵɵelementEnd()();
53
+ i0.ɵɵelementStart(9, "td", 7);
54
+ i0.ɵɵlistener("click", function EntityPermissionsGridComponent_table_3_tr_14_Template_td_click_9_listener($event) { const restoredCtx = i0.ɵɵrestoreView(_r8); const permission_r6 = restoredCtx.$implicit; const ctx_r17 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r17.flipPermission($event, permission_r6, "Delete", true)); });
55
+ i0.ɵɵelementStart(10, "input", 8);
56
+ i0.ɵɵtwoWayListener("ngModelChange", function EntityPermissionsGridComponent_table_3_tr_14_Template_input_ngModelChange_10_listener($event) { const restoredCtx = i0.ɵɵrestoreView(_r8); const permission_r6 = restoredCtx.$implicit; i0.ɵɵtwoWayBindingSet(permission_r6.CanDelete, $event) || (permission_r6.CanDelete = $event); return i0.ɵɵresetView($event); });
57
+ i0.ɵɵlistener("click", function EntityPermissionsGridComponent_table_3_tr_14_Template_input_click_10_listener($event) { const restoredCtx = i0.ɵɵrestoreView(_r8); const permission_r6 = restoredCtx.$implicit; const ctx_r19 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r19.flipPermission($event, permission_r6, "Delete", false)); });
58
+ i0.ɵɵelementEnd()()();
59
+ } if (rf & 2) {
60
+ const permission_r6 = ctx.$implicit;
61
+ i0.ɵɵadvance(2);
62
+ i0.ɵɵtextInterpolate(permission_r6.RoleName);
63
+ i0.ɵɵadvance(2);
64
+ i0.ɵɵtwoWayProperty("ngModel", permission_r6.CanRead);
65
+ i0.ɵɵadvance(2);
66
+ i0.ɵɵtwoWayProperty("ngModel", permission_r6.CanUpdate);
67
+ i0.ɵɵadvance(2);
68
+ i0.ɵɵtwoWayProperty("ngModel", permission_r6.CanCreate);
69
+ i0.ɵɵadvance(2);
70
+ i0.ɵɵtwoWayProperty("ngModel", permission_r6.CanDelete);
71
+ } }
72
+ function EntityPermissionsGridComponent_table_3_Template(rf, ctx) { if (rf & 1) {
73
+ i0.ɵɵelementStart(0, "table", 5)(1, "thead")(2, "tr")(3, "th");
74
+ i0.ɵɵtext(4, "Role");
75
+ i0.ɵɵelementEnd();
76
+ i0.ɵɵelementStart(5, "th");
77
+ i0.ɵɵtext(6, "Read");
78
+ i0.ɵɵelementEnd();
79
+ i0.ɵɵelementStart(7, "th");
80
+ i0.ɵɵtext(8, "Update");
81
+ i0.ɵɵelementEnd();
82
+ i0.ɵɵelementStart(9, "th");
83
+ i0.ɵɵtext(10, "Create");
84
+ i0.ɵɵelementEnd();
85
+ i0.ɵɵelementStart(11, "th");
86
+ i0.ɵɵtext(12, "Delete");
87
+ i0.ɵɵelementEnd()()();
88
+ i0.ɵɵelementStart(13, "tbody");
89
+ i0.ɵɵtemplate(14, EntityPermissionsGridComponent_table_3_tr_14_Template, 11, 5, "tr", 6);
90
+ i0.ɵɵelementEnd()();
91
+ } if (rf & 2) {
92
+ const ctx_r2 = i0.ɵɵnextContext();
93
+ i0.ɵɵadvance(14);
94
+ i0.ɵɵproperty("ngForOf", ctx_r2.permissions);
95
+ } }
96
+ export class EntityPermissionsGridComponent {
97
+ constructor() {
98
+ this.BottomMargin = 0;
99
+ this.PermissionChanged = new EventEmitter();
100
+ this.permissions = [];
101
+ this.gridHeight = 750;
102
+ this.isLoading = false;
103
+ this.kendoSVGIcon = kendoSVGIcon;
104
+ }
105
+ ngOnInit() {
106
+ this.Refresh();
107
+ }
108
+ ngOnChanges(changes) {
109
+ if (changes.EntityName && !changes.EntityName.isFirstChange()) {
110
+ // If EntityName has changed and it's not the first change (initialization)
111
+ this.Refresh();
112
+ }
113
+ }
114
+ Refresh() {
115
+ return __awaiter(this, void 0, void 0, function* () {
116
+ if (this.EntityName && this.EntityName.length > 0) {
117
+ const startTime = new Date().getTime();
118
+ this.isLoading = true;
119
+ const md = new Metadata();
120
+ const e = md.Entities.find(e => e.Name === this.EntityName);
121
+ if (!e)
122
+ throw new Error("Entity not found: " + this.EntityName);
123
+ const rv = new RunView();
124
+ const result = yield rv.RunView({
125
+ EntityName: 'Entity Permissions',
126
+ ExtraFilter: 'EntityID=' + e.ID,
127
+ OrderBy: 'RoleName ASC',
128
+ ResultType: 'entity_object'
129
+ });
130
+ if (result.Success) {
131
+ // we have all of the saved permissions now
132
+ // the post-process we need to do now is to see if there are any roles that don't have any existing permissions and if so, we need to create
133
+ // new permission records for them. We won't actually consider those "Dirty" and save those unless the user actually selects one or more
134
+ // to turn on, we are just doing this to make the grid easy to manage from the user perspective.
135
+ const existingPermissions = result.Results;
136
+ const roles = md.Roles;
137
+ const rolesWithNoPermissions = roles.filter(r => !existingPermissions.some(p => p.RoleName === r.Name));
138
+ for (const r of rolesWithNoPermissions) {
139
+ const p = yield md.GetEntityObject('Entity Permissions');
140
+ p.NewRecord();
141
+ p.EntityID = e.ID;
142
+ p.RoleName = r.Name;
143
+ p.CanRead = false;
144
+ p.CanCreate = false;
145
+ p.CanUpdate = false;
146
+ p.CanDelete = false;
147
+ existingPermissions.push(p);
148
+ }
149
+ this.permissions = existingPermissions.sort((a, b) => a.RoleName.localeCompare(b.RoleName));
150
+ }
151
+ else {
152
+ throw new Error("Error loading entity permissions: " + result.ErrorMessage);
153
+ }
154
+ this.isLoading = false;
155
+ }
156
+ });
157
+ }
158
+ savePermissions() {
159
+ return __awaiter(this, void 0, void 0, function* () {
160
+ // iterate through each permisison and for the ones that are dirty, add to transaction group then commit at once
161
+ const md = new Metadata();
162
+ const tg = yield md.CreateTransactionGroup();
163
+ let itemCount = 0;
164
+ this.permissions.forEach(p => {
165
+ if (this.IsPermissionReallyDirty(p)) {
166
+ p.TransactionGroup = tg;
167
+ itemCount++;
168
+ p.Save(); // don't await since we are using a tg
169
+ }
170
+ });
171
+ if (itemCount > 0)
172
+ yield tg.Submit();
173
+ });
174
+ }
175
+ get NumDirtyPermissions() {
176
+ return this.permissions.filter(p => this.IsPermissionReallyDirty(p)).length;
177
+ }
178
+ IsPermissionReallyDirty(p) {
179
+ if (!p.Dirty)
180
+ return false;
181
+ else if (p.ID > 0)
182
+ return true;
183
+ else
184
+ return p.CanRead || p.CanCreate || p.CanUpdate || p.CanDelete; // if we have a new record, only consider it dirty if at least one permission is true
185
+ }
186
+ flipPermission(event, permission, type, flipPermission) {
187
+ if (flipPermission) {
188
+ switch (type) {
189
+ case 'Read':
190
+ permission.CanRead = !permission.CanRead;
191
+ break;
192
+ case 'Create':
193
+ permission.CanCreate = !permission.CanCreate;
194
+ break;
195
+ case 'Update':
196
+ permission.CanUpdate = !permission.CanUpdate;
197
+ break;
198
+ case 'Delete':
199
+ permission.CanDelete = !permission.CanDelete;
200
+ break;
201
+ }
202
+ }
203
+ // always fire the event
204
+ const value = type === 'Read' ? permission.CanRead : type === 'Create' ? permission.CanCreate : type === 'Update' ? permission.CanUpdate : permission.CanDelete;
205
+ this.PermissionChanged.emit({
206
+ EntityName: this.EntityName,
207
+ RoleName: permission.RoleName,
208
+ PermissionTypeChanged: type,
209
+ Value: value,
210
+ Cancel: false
211
+ });
212
+ if (!flipPermission)
213
+ event.stopPropagation();
214
+ }
215
+ }
216
+ EntityPermissionsGridComponent.ɵfac = function EntityPermissionsGridComponent_Factory(t) { return new (t || EntityPermissionsGridComponent)(); };
217
+ EntityPermissionsGridComponent.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: EntityPermissionsGridComponent, selectors: [["mj-entity-permissions-grid"]], inputs: { EntityName: "EntityName", BottomMargin: "BottomMargin" }, outputs: { PermissionChanged: "PermissionChanged" }, features: [i0.ɵɵNgOnChangesFeature], decls: 4, vars: 3, consts: [["mjFillContainer", ""], [4, "ngIf"], ["kendoButton", "", 3, "click", 4, "ngIf"], ["class", "grid", 4, "ngIf"], ["kendoButton", "", 3, "click"], [1, "grid"], [4, "ngFor", "ngForOf"], [3, "click"], ["type", "checkbox", "kendoCheckBox", "", 3, "ngModel", "ngModelChange", "click"]], template: function EntityPermissionsGridComponent_Template(rf, ctx) { if (rf & 1) {
218
+ i0.ɵɵelementStart(0, "div", 0);
219
+ i0.ɵɵtemplate(1, EntityPermissionsGridComponent_div_1_Template, 2, 0, "div", 1)(2, EntityPermissionsGridComponent_button_2_Template, 2, 0, "button", 2)(3, EntityPermissionsGridComponent_table_3_Template, 15, 1, "table", 3);
220
+ i0.ɵɵelementEnd();
221
+ } if (rf & 2) {
222
+ i0.ɵɵadvance();
223
+ i0.ɵɵproperty("ngIf", ctx.isLoading);
224
+ i0.ɵɵadvance();
225
+ i0.ɵɵproperty("ngIf", ctx.NumDirtyPermissions > 0);
226
+ i0.ɵɵadvance();
227
+ i0.ɵɵproperty("ngIf", !ctx.isLoading);
228
+ } }, dependencies: [i1.NgForOf, i1.NgIf, i2.CheckboxControlValueAccessor, i2.NgControlStatus, i2.NgModel, i3.FillContainer, i4.ButtonComponent], styles: ["\n\r\ntable[_ngcontent-%COMP%] {\r\n margin-left: 5px;\r\n margin-top: 5px;\r\n border-collapse: collapse; \n\r\n}\r\n\r\nbutton[_ngcontent-%COMP%] {\r\n margin-left: 5px;\r\n margin-top: 5px;\r\n}\r\n \r\ntable[_ngcontent-%COMP%] th[_ngcontent-%COMP%] {\r\n background-color: #f2f2f2; \n\r\n color: black; \n\r\n font-weight: bold; \n\r\n}\r\n\r\n\n\r\ntable[_ngcontent-%COMP%] th[_ngcontent-%COMP%], table[_ngcontent-%COMP%] td[_ngcontent-%COMP%] {\r\n border: 1px solid gray; \n\r\n height: 36px; \n\r\n text-align: center;\r\n padding: 0 8px; \n\r\n}\r\n\r\n\n\r\ntable[_ngcontent-%COMP%] th[_ngcontent-%COMP%]:first-child, table[_ngcontent-%COMP%] td[_ngcontent-%COMP%]:first-child {\r\n width: 150px; \n\r\n text-align: left;\r\n}\r\n\r\n\n\r\ntable[_ngcontent-%COMP%] th[_ngcontent-%COMP%]:not(:first-child), table[_ngcontent-%COMP%] td[_ngcontent-%COMP%]:not(:first-child) {\r\n width: 100px; \n\r\n}\r\n\r\n\n\r\ntable[_ngcontent-%COMP%] tr[_ngcontent-%COMP%]:nth-child(odd) {\r\n background-color: white; \n\r\n}\r\n\r\ntable[_ngcontent-%COMP%] tr[_ngcontent-%COMP%]:nth-child(even) {\r\n background-color: #e7f4ff; \n\r\n}"] });
229
+ (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(EntityPermissionsGridComponent, [{
230
+ type: Component,
231
+ args: [{ selector: 'mj-entity-permissions-grid', template: "<div mjFillContainer>\r\n <!-- We are going to do a simple custom grid here because Kendo Grid is way too much for this and doesn't show checkboxes even when not editing, this is cleaner and simpler -->\r\n <!-- Assuming your component's selector is 'app-permissions-grid' -->\r\n <div *ngIf=\"isLoading\">Loading permissions...</div>\r\n <button *ngIf=\"NumDirtyPermissions > 0\" kendoButton (click)=\"savePermissions()\">Save</button>\r\n <table *ngIf=\"!isLoading\" class=\"grid\">\r\n <thead>\r\n <tr>\r\n <th>Role</th>\r\n <th>Read</th>\r\n <th>Update</th>\r\n <th>Create</th>\r\n <th>Delete</th>\r\n </tr>\r\n </thead>\r\n <tbody>\r\n <tr *ngFor=\"let permission of permissions\">\r\n <td>{{ permission.RoleName }}</td>\r\n <td (click)=\"flipPermission($event, permission, 'Read', true)\">\r\n <input type=\"checkbox\" kendoCheckBox [(ngModel)]=\"permission.CanRead\" (click)=\"flipPermission($event, permission, 'Read', false)\">\r\n </td>\r\n <td (click)=\"flipPermission($event, permission, 'Update', true)\">\r\n <input type=\"checkbox\" kendoCheckBox [(ngModel)]=\"permission.CanUpdate\" (click)=\"flipPermission($event, permission, 'Update', false)\">\r\n </td>\r\n <td (click)=\"flipPermission($event, permission, 'Create', true)\">\r\n <input type=\"checkbox\" kendoCheckBox [(ngModel)]=\"permission.CanCreate\" (click)=\"flipPermission($event, permission, 'Create', false)\">\r\n </td>\r\n <td (click)=\"flipPermission($event, permission, 'Delete', true)\">\r\n <input type=\"checkbox\" kendoCheckBox [(ngModel)]=\"permission.CanDelete\" (click)=\"flipPermission($event, permission, 'Delete', false)\">\r\n </td>\r\n </tr>\r\n </tbody>\r\n </table>\r\n</div>\r\n ", styles: ["/* Style for the whole table */\r\ntable {\r\n margin-left: 5px;\r\n margin-top: 5px;\r\n border-collapse: collapse; /* Ensures border collapse for a cleaner look */\r\n}\r\n\r\nbutton {\r\n margin-left: 5px;\r\n margin-top: 5px;\r\n}\r\n \r\ntable th {\r\n background-color: #f2f2f2; /* Light gray background for headers */\r\n color: black; /* Black text color for headers */\r\n font-weight: bold; /* Bold font weight for headers */\r\n}\r\n\r\n/* Style for all table cells */\r\ntable th, table td {\r\n border: 1px solid gray; /* Gray border for cells */\r\n height: 36px; /* Fixed height for all rows */\r\n text-align: center;\r\n padding: 0 8px; /* Add some padding inside cells */\r\n}\r\n\r\n/* Specific styles for the first column */\r\ntable th:first-child, table td:first-child {\r\n width: 150px; /* Set width for the first column */\r\n text-align: left;\r\n}\r\n\r\n/* Specific styles for the \"Can\" columns */\r\ntable th:not(:first-child), table td:not(:first-child) {\r\n width: 100px; /* Set width for \"Can\" columns */\r\n}\r\n\r\n/* Alternating row background colors */\r\ntable tr:nth-child(odd) {\r\n background-color: white; /* Light color for odd rows */\r\n}\r\n\r\ntable tr:nth-child(even) {\r\n background-color: #e7f4ff; /* Light blue for even rows */\r\n}\r\n"] }]
232
+ }], () => [], { EntityName: [{
233
+ type: Input
234
+ }], BottomMargin: [{
235
+ type: Input
236
+ }], PermissionChanged: [{
237
+ type: Output
238
+ }] }); })();
239
+ (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(EntityPermissionsGridComponent, { className: "EntityPermissionsGridComponent", filePath: "src\\lib\\grid\\entity-permissions-grid.component.ts", lineNumber: 21 }); })();
@@ -0,0 +1,18 @@
1
+ import * as i0 from "@angular/core";
2
+ import * as i1 from "./grid/entity-permissions-grid.component";
3
+ import * as i2 from "./entity-selector-with-grid/entity-selector-with-grid.component";
4
+ import * as i3 from "@angular/common";
5
+ import * as i4 from "@progress/kendo-angular-grid";
6
+ import * as i5 from "@angular/forms";
7
+ import * as i6 from "@progress/kendo-angular-dialog";
8
+ import * as i7 from "@progress/kendo-angular-excel-export";
9
+ import * as i8 from "@memberjunction/ng-compare-records";
10
+ import * as i9 from "@memberjunction/ng-container-directives";
11
+ import * as i10 from "@progress/kendo-angular-buttons";
12
+ import * as i11 from "@progress/kendo-angular-icons";
13
+ import * as i12 from "@progress/kendo-angular-dropdowns";
14
+ export declare class EntityPermissionsModule {
15
+ static ɵfac: i0.ɵɵFactoryDeclaration<EntityPermissionsModule, never>;
16
+ static ɵmod: i0.ɵɵNgModuleDeclaration<EntityPermissionsModule, [typeof i1.EntityPermissionsGridComponent, typeof i2.EntityPermissionsSelectorWithGridComponent], [typeof i3.CommonModule, typeof i4.GridModule, typeof i5.FormsModule, typeof i6.DialogsModule, typeof i7.ExcelExportModule, typeof i8.CompareRecordsModule, typeof i9.ContainerDirectivesModule, typeof i10.ButtonsModule, typeof i11.IconsModule, typeof i12.DropDownsModule], [typeof i1.EntityPermissionsGridComponent, typeof i2.EntityPermissionsSelectorWithGridComponent]>;
17
+ static ɵinj: i0.ɵɵInjectorDeclaration<EntityPermissionsModule>;
18
+ }
@@ -0,0 +1,66 @@
1
+ import { NgModule } from '@angular/core';
2
+ import { EntityPermissionsGridComponent } from './grid/entity-permissions-grid.component';
3
+ import { CommonModule } from '@angular/common';
4
+ // Kendo UI Angular imports
5
+ import { GridModule } from '@progress/kendo-angular-grid';
6
+ import { ExcelExportModule } from '@progress/kendo-angular-excel-export';
7
+ import { DialogsModule } from "@progress/kendo-angular-dialog";
8
+ import { ButtonsModule } from '@progress/kendo-angular-buttons';
9
+ import { IconsModule } from '@progress/kendo-angular-icons';
10
+ import { CompareRecordsModule } from '@memberjunction/ng-compare-records';
11
+ import { ContainerDirectivesModule } from '@memberjunction/ng-container-directives';
12
+ import { FormsModule } from '@angular/forms';
13
+ import { EntityPermissionsSelectorWithGridComponent } from './entity-selector-with-grid/entity-selector-with-grid.component';
14
+ import { DropDownsModule } from '@progress/kendo-angular-dropdowns';
15
+ import * as i0 from "@angular/core";
16
+ export class EntityPermissionsModule {
17
+ }
18
+ EntityPermissionsModule.ɵfac = function EntityPermissionsModule_Factory(t) { return new (t || EntityPermissionsModule)(); };
19
+ EntityPermissionsModule.ɵmod = /*@__PURE__*/ i0.ɵɵdefineNgModule({ type: EntityPermissionsModule });
20
+ EntityPermissionsModule.ɵinj = /*@__PURE__*/ i0.ɵɵdefineInjector({ imports: [CommonModule,
21
+ GridModule,
22
+ FormsModule,
23
+ DialogsModule,
24
+ ExcelExportModule,
25
+ CompareRecordsModule,
26
+ ContainerDirectivesModule,
27
+ ButtonsModule,
28
+ IconsModule,
29
+ DropDownsModule] });
30
+ (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(EntityPermissionsModule, [{
31
+ type: NgModule,
32
+ args: [{
33
+ declarations: [
34
+ EntityPermissionsGridComponent,
35
+ EntityPermissionsSelectorWithGridComponent
36
+ ],
37
+ imports: [
38
+ CommonModule,
39
+ GridModule,
40
+ FormsModule,
41
+ DialogsModule,
42
+ ExcelExportModule,
43
+ CompareRecordsModule,
44
+ ContainerDirectivesModule,
45
+ ButtonsModule,
46
+ IconsModule,
47
+ DropDownsModule
48
+ ],
49
+ exports: [
50
+ EntityPermissionsGridComponent,
51
+ EntityPermissionsSelectorWithGridComponent
52
+ ]
53
+ }]
54
+ }], null, null); })();
55
+ (function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0.ɵɵsetNgModuleScope(EntityPermissionsModule, { declarations: [EntityPermissionsGridComponent,
56
+ EntityPermissionsSelectorWithGridComponent], imports: [CommonModule,
57
+ GridModule,
58
+ FormsModule,
59
+ DialogsModule,
60
+ ExcelExportModule,
61
+ CompareRecordsModule,
62
+ ContainerDirectivesModule,
63
+ ButtonsModule,
64
+ IconsModule,
65
+ DropDownsModule], exports: [EntityPermissionsGridComponent,
66
+ EntityPermissionsSelectorWithGridComponent] }); })();
@@ -0,0 +1,3 @@
1
+ export * from './lib/entity-selector-with-grid/entity-selector-with-grid.component';
2
+ export * from './lib/grid/entity-permissions-grid.component';
3
+ export * from './lib/module';
@@ -0,0 +1,6 @@
1
+ /*
2
+ * Public API Surface
3
+ */
4
+ export * from './lib/entity-selector-with-grid/entity-selector-with-grid.component';
5
+ export * from './lib/grid/entity-permissions-grid.component';
6
+ export * from './lib/module';
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@memberjunction/ng-entity-permissions",
3
+ "version": "0.9.2",
4
+ "description": "MemberJunction: Angular components for displaying/editing permissions for an entity, and related components.",
5
+ "main": "./dist/public-api.js",
6
+ "typings": "./dist/public-api.d.ts",
7
+ "files": [
8
+ "/dist"
9
+ ],
10
+ "scripts": {
11
+ "test": "echo \"Error: no test specified\" && exit 1",
12
+ "build": "ngc"
13
+ },
14
+ "keywords": [],
15
+ "author": "",
16
+ "license": "ISC",
17
+ "devDependencies": {
18
+ "@angular/compiler": "~17.2.2",
19
+ "@angular/compiler-cli": "~17.2.2"
20
+ },
21
+ "peerDependencies": {
22
+ "@angular/common": "~17.2.2",
23
+ "@angular/core": "~17.2.2",
24
+ "@angular/forms": "~17.2.2",
25
+ "@angular/router": "~17.2.2"
26
+ },
27
+ "dependencies": {
28
+ "@memberjunction/core-entities": "^0.9.156",
29
+ "@memberjunction/global": "^0.9.153",
30
+ "@memberjunction/core": "^0.9.172",
31
+ "@memberjunction/ng-container-directives": "^0.9.136",
32
+ "@memberjunction/ng-shared": "^0.9.25",
33
+ "@progress/kendo-angular-dropdowns": "~15.1.0",
34
+ "@progress/kendo-angular-grid": "~15.1.0",
35
+ "@progress/kendo-angular-buttons": "~15.1.0",
36
+ "@progress/kendo-angular-dialog": "~15.1.0",
37
+ "tslib": "^2.3.0"
38
+ },
39
+ "sideEffects": false
40
+ }