@sprucelabs/spruce-role-utils 0.1.113 → 0.2.0

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,2 @@
1
+ export { default as RoleSelectCardViewController } from './selectingRoles/RoleSelectCard.vc';
2
+ export * from './selectingRoles/RoleSelectCard.vc';
@@ -1,3 +1,2 @@
1
- "use strict";
2
- // export { default as RoleSelectCardViewController } from './adding/RoleSelectCard.vc.js'
3
- // export * from './types-module.js'
1
+ export { default as RoleSelectCardViewController } from './selectingRoles/RoleSelectCard.vc.js';
2
+ export * from './selectingRoles/RoleSelectCard.vc.js';
@@ -0,0 +1,35 @@
1
+ import { AbstractViewController, ActiveRecordCardViewController, Card, CardFooter, CardHeader, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
2
+ export default class RoleSelectCardViewController extends AbstractViewController<Card> {
3
+ static id: string;
4
+ private isLoaded;
5
+ protected activeCardVc: ActiveRecordCardViewController;
6
+ private changeHandler?;
7
+ constructor(options: ViewControllerOptions & RoleSelectCardOptions);
8
+ private RoleListVc;
9
+ private renderRow;
10
+ private handleClickEnableCheckbox;
11
+ private handleDidChange;
12
+ getIsLoaded(): boolean;
13
+ setIsBusy(isBusy: boolean): void;
14
+ load(options: RoleSelectCardLoadOptions): Promise<void>;
15
+ getSelectedRoles(): SelectedRoleWithRequirement[];
16
+ private enableRow;
17
+ private rowVc;
18
+ render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
19
+ }
20
+ export interface RoleSelectCardOptions {
21
+ header?: CardHeader;
22
+ footer?: CardFooter;
23
+ onChange?: ChangeHandler;
24
+ }
25
+ declare type ChangeHandler = (values: SelectedRoleWithRequirement[]) => void | Promise<void>;
26
+ export declare type RoleRequirement = 'optional' | 'required';
27
+ export interface SelectedRoleWithRequirement {
28
+ roleId: string;
29
+ requirement: RoleRequirement;
30
+ }
31
+ export interface RoleSelectCardLoadOptions {
32
+ organizationId: string;
33
+ selected?: SelectedRoleWithRequirement[];
34
+ }
35
+ export {};
@@ -0,0 +1,121 @@
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 { AbstractViewController, buildActiveRecordCard, } from '@sprucelabs/heartwood-view-controllers';
11
+ import { assertOptions } from '@sprucelabs/schema';
12
+ export default class RoleSelectCardViewController extends AbstractViewController {
13
+ constructor(options) {
14
+ super(options);
15
+ this.isLoaded = false;
16
+ const { onChange } = options;
17
+ this.changeHandler = onChange;
18
+ this.activeCardVc = this.RoleListVc(options);
19
+ }
20
+ RoleListVc(options) {
21
+ return this.Controller('activeRecordCard', buildActiveRecordCard(Object.assign(Object.assign({ id: 'role-select', eventName: 'list-roles::v2020_12_25', responseKey: 'roles', columnWidths: ['content', 'fill'], payload: {
22
+ shouldIncludeMetaRoles: false,
23
+ shouldIncludePrivateRoles: true,
24
+ } }, options), { rowTransformer: this.renderRow.bind(this) })));
25
+ }
26
+ renderRow(role) {
27
+ return {
28
+ id: role.id,
29
+ isEnabled: false,
30
+ cells: [
31
+ {
32
+ checkboxInput: {
33
+ name: 'isEnabled',
34
+ onChange: (enabled) => __awaiter(this, void 0, void 0, function* () {
35
+ yield this.handleClickEnableCheckbox(role.id, enabled);
36
+ }),
37
+ },
38
+ },
39
+ {
40
+ text: {
41
+ content: role.name,
42
+ },
43
+ },
44
+ {
45
+ selectInput: {
46
+ name: 'requirement',
47
+ isRequired: true,
48
+ value: 'optional',
49
+ onChange: this.handleDidChange.bind(this),
50
+ choices: [
51
+ {
52
+ value: 'optional',
53
+ label: 'Optional',
54
+ },
55
+ {
56
+ value: 'required',
57
+ label: 'Required',
58
+ },
59
+ ],
60
+ },
61
+ },
62
+ ],
63
+ };
64
+ }
65
+ handleClickEnableCheckbox(id, enabled) {
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ this.activeCardVc.getRowVc(id).setIsEnabled(enabled);
68
+ yield this.handleDidChange();
69
+ });
70
+ }
71
+ handleDidChange() {
72
+ var _a;
73
+ return __awaiter(this, void 0, void 0, function* () {
74
+ yield ((_a = this.changeHandler) === null || _a === void 0 ? void 0 : _a.call(this, this.getSelectedRoles()));
75
+ });
76
+ }
77
+ getIsLoaded() {
78
+ return this.isLoaded;
79
+ }
80
+ setIsBusy(isBusy) {
81
+ this.activeCardVc.setIsBusy(isBusy);
82
+ }
83
+ load(options) {
84
+ return __awaiter(this, void 0, void 0, function* () {
85
+ const { organizationId, selected } = assertOptions(options, [
86
+ 'organizationId',
87
+ ]);
88
+ this.activeCardVc.setTarget({
89
+ organizationId,
90
+ });
91
+ yield this.activeCardVc.load();
92
+ this.isLoaded = true;
93
+ for (const select of selected !== null && selected !== void 0 ? selected : []) {
94
+ yield this.enableRow(select.roleId, select.requirement);
95
+ }
96
+ });
97
+ }
98
+ getSelectedRoles() {
99
+ const values = this.activeCardVc.getValues();
100
+ return values
101
+ .map((v) => ({
102
+ roleId: v.rowId,
103
+ requirement: v.requirement,
104
+ }))
105
+ .filter((v) => this.rowVc(v.roleId).getIsEnabled());
106
+ }
107
+ enableRow(roleId, requirement) {
108
+ return __awaiter(this, void 0, void 0, function* () {
109
+ const rowVc = this.rowVc(roleId);
110
+ rowVc.setIsEnabled(true);
111
+ yield rowVc.setValue('requirement', requirement);
112
+ });
113
+ }
114
+ rowVc(roleId) {
115
+ return this.activeCardVc.getRowVc(roleId);
116
+ }
117
+ render() {
118
+ return this.activeCardVc.render();
119
+ }
120
+ }
121
+ RoleSelectCardViewController.id = 'role-select-card';
@@ -0,0 +1,2 @@
1
+ export { default as RoleSelectCardViewController } from './selectingRoles/RoleSelectCard.vc';
2
+ export * from './selectingRoles/RoleSelectCard.vc';
@@ -1,3 +1,23 @@
1
1
  "use strict";
2
- // export { default as RoleSelectCardViewController } from './adding/RoleSelectCard.vc'
3
- // export * from './types-module'
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.RoleSelectCardViewController = void 0;
21
+ var RoleSelectCard_vc_1 = require("./selectingRoles/RoleSelectCard.vc");
22
+ Object.defineProperty(exports, "RoleSelectCardViewController", { enumerable: true, get: function () { return __importDefault(RoleSelectCard_vc_1).default; } });
23
+ __exportStar(require("./selectingRoles/RoleSelectCard.vc"), exports);
@@ -0,0 +1,35 @@
1
+ import { AbstractViewController, ActiveRecordCardViewController, Card, CardFooter, CardHeader, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
2
+ export default class RoleSelectCardViewController extends AbstractViewController<Card> {
3
+ static id: string;
4
+ private isLoaded;
5
+ protected activeCardVc: ActiveRecordCardViewController;
6
+ private changeHandler?;
7
+ constructor(options: ViewControllerOptions & RoleSelectCardOptions);
8
+ private RoleListVc;
9
+ private renderRow;
10
+ private handleClickEnableCheckbox;
11
+ private handleDidChange;
12
+ getIsLoaded(): boolean;
13
+ setIsBusy(isBusy: boolean): void;
14
+ load(options: RoleSelectCardLoadOptions): Promise<void>;
15
+ getSelectedRoles(): SelectedRoleWithRequirement[];
16
+ private enableRow;
17
+ private rowVc;
18
+ render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
19
+ }
20
+ export interface RoleSelectCardOptions {
21
+ header?: CardHeader;
22
+ footer?: CardFooter;
23
+ onChange?: ChangeHandler;
24
+ }
25
+ declare type ChangeHandler = (values: SelectedRoleWithRequirement[]) => void | Promise<void>;
26
+ export declare type RoleRequirement = 'optional' | 'required';
27
+ export interface SelectedRoleWithRequirement {
28
+ roleId: string;
29
+ requirement: RoleRequirement;
30
+ }
31
+ export interface RoleSelectCardLoadOptions {
32
+ organizationId: string;
33
+ selected?: SelectedRoleWithRequirement[];
34
+ }
35
+ export {};
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const heartwood_view_controllers_1 = require("@sprucelabs/heartwood-view-controllers");
4
+ const schema_1 = require("@sprucelabs/schema");
5
+ class RoleSelectCardViewController extends heartwood_view_controllers_1.AbstractViewController {
6
+ constructor(options) {
7
+ super(options);
8
+ this.isLoaded = false;
9
+ const { onChange } = options;
10
+ this.changeHandler = onChange;
11
+ this.activeCardVc = this.RoleListVc(options);
12
+ }
13
+ RoleListVc(options) {
14
+ return this.Controller('activeRecordCard', (0, heartwood_view_controllers_1.buildActiveRecordCard)(Object.assign(Object.assign({ id: 'role-select', eventName: 'list-roles::v2020_12_25', responseKey: 'roles', columnWidths: ['content', 'fill'], payload: {
15
+ shouldIncludeMetaRoles: false,
16
+ shouldIncludePrivateRoles: true,
17
+ } }, options), { rowTransformer: this.renderRow.bind(this) })));
18
+ }
19
+ renderRow(role) {
20
+ return {
21
+ id: role.id,
22
+ isEnabled: false,
23
+ cells: [
24
+ {
25
+ checkboxInput: {
26
+ name: 'isEnabled',
27
+ onChange: async (enabled) => {
28
+ await this.handleClickEnableCheckbox(role.id, enabled);
29
+ },
30
+ },
31
+ },
32
+ {
33
+ text: {
34
+ content: role.name,
35
+ },
36
+ },
37
+ {
38
+ selectInput: {
39
+ name: 'requirement',
40
+ isRequired: true,
41
+ value: 'optional',
42
+ onChange: this.handleDidChange.bind(this),
43
+ choices: [
44
+ {
45
+ value: 'optional',
46
+ label: 'Optional',
47
+ },
48
+ {
49
+ value: 'required',
50
+ label: 'Required',
51
+ },
52
+ ],
53
+ },
54
+ },
55
+ ],
56
+ };
57
+ }
58
+ async handleClickEnableCheckbox(id, enabled) {
59
+ this.activeCardVc.getRowVc(id).setIsEnabled(enabled);
60
+ await this.handleDidChange();
61
+ }
62
+ async handleDidChange() {
63
+ var _a;
64
+ await ((_a = this.changeHandler) === null || _a === void 0 ? void 0 : _a.call(this, this.getSelectedRoles()));
65
+ }
66
+ getIsLoaded() {
67
+ return this.isLoaded;
68
+ }
69
+ setIsBusy(isBusy) {
70
+ this.activeCardVc.setIsBusy(isBusy);
71
+ }
72
+ async load(options) {
73
+ const { organizationId, selected } = (0, schema_1.assertOptions)(options, [
74
+ 'organizationId',
75
+ ]);
76
+ this.activeCardVc.setTarget({
77
+ organizationId,
78
+ });
79
+ await this.activeCardVc.load();
80
+ this.isLoaded = true;
81
+ for (const select of selected !== null && selected !== void 0 ? selected : []) {
82
+ await this.enableRow(select.roleId, select.requirement);
83
+ }
84
+ }
85
+ getSelectedRoles() {
86
+ const values = this.activeCardVc.getValues();
87
+ return values
88
+ .map((v) => ({
89
+ roleId: v.rowId,
90
+ requirement: v.requirement,
91
+ }))
92
+ .filter((v) => this.rowVc(v.roleId).getIsEnabled());
93
+ }
94
+ async enableRow(roleId, requirement) {
95
+ const rowVc = this.rowVc(roleId);
96
+ rowVc.setIsEnabled(true);
97
+ await rowVc.setValue('requirement', requirement);
98
+ }
99
+ rowVc(roleId) {
100
+ return this.activeCardVc.getRowVc(roleId);
101
+ }
102
+ render() {
103
+ return this.activeCardVc.render();
104
+ }
105
+ }
106
+ exports.default = RoleSelectCardViewController;
107
+ RoleSelectCardViewController.id = 'role-select-card';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sprucelabs/spruce-role-utils",
3
3
  "description": "Useful role utilities",
4
- "version": "0.1.113",
4
+ "version": "0.2.0",
5
5
  "skill": {
6
6
  "namespace": "role"
7
7
  },
@@ -14,24 +14,14 @@
14
14
  "module": "./build/esm/index-module.js",
15
15
  "sideEffects": false,
16
16
  "files": [
17
- "build/index-module.js",
18
- "build/index-module.d.ts",
19
- "build/esm/index-module.js",
20
- "build/esm/index-module.d.ts"
21
- ],
22
- "oldFiles": [
23
17
  "build/index-module.js",
24
18
  "build/index-module.d.ts",
25
19
  "build/esm/index-module.js",
26
20
  "build/esm/index-module.d.ts",
27
- "build/adding/RoleSelectCard.vc.js",
28
- "build/adding/RoleSelectCard.vc.d.ts",
29
- "build/esm/adding/RoleSelectCard.vc.js",
30
- "build/esm/adding/RoleSelectCard.vc.d.ts",
31
- "build/types-module.js",
32
- "build/types-module.d.ts",
33
- "build/esm/types-module.js",
34
- "build/esm/types-module.d.ts"
21
+ "build/selectingRoles/RoleSelectCard.vc.js",
22
+ "build/selectingRoles/RoleSelectCard.vc.d.ts",
23
+ "build/esm/selectingRoles/RoleSelectCard.vc.js",
24
+ "build/esm/selectingRoles/RoleSelectCard.vc.d.ts"
35
25
  ],
36
26
  "keywords": [],
37
27
  "scripts": {