@sprucelabs/spruce-profile-utils 1.2.64 → 1.2.66

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.
@@ -119,4 +119,3 @@ class RoleSelectCardViewController extends heartwood_view_controllers_1.Abstract
119
119
  }
120
120
  exports.default = RoleSelectCardViewController;
121
121
  RoleSelectCardViewController.id = 'role-select-card';
122
- //# sourceMappingURL=RoleSelectCard.vc.js.map
@@ -0,0 +1,33 @@
1
+ import { AbstractViewController, ActiveRecordCardViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
2
+ export default class RoleSelectCardViewController extends AbstractViewController<Card> {
3
+ static id: string;
4
+ private activeRecordCardVc;
5
+ private isLoaded;
6
+ private onChangeHandler?;
7
+ private roles;
8
+ constructor(options: RoleSelectCardViewControllerOptions);
9
+ private ActiveRecordVc;
10
+ getCardVc(): import("@sprucelabs/heartwood-view-controllers").CardViewController;
11
+ getActiveRecordCardVc(): ActiveRecordCardViewController;
12
+ getListVc(): import("@sprucelabs/heartwood-view-controllers").ListViewController;
13
+ getRoles(): ProfileRole[];
14
+ setRoles(roles: Roles): Promise<void>;
15
+ getIsLoaded(): boolean;
16
+ private buildRoleRow;
17
+ private getRequirementsForRole;
18
+ load(options: {
19
+ organizationId: string;
20
+ }): Promise<void>;
21
+ render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
22
+ }
23
+ declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
24
+ declare type OnChangeHandler = (roleId: string, value: string) => Promise<void> | void;
25
+ export interface ProfileRole {
26
+ roleId: string;
27
+ requirements: 'optional' | 'required';
28
+ }
29
+ declare type Roles = ProfileRole[];
30
+ export declare type RoleSelectCardViewControllerOptions = ViewControllerOptions & {
31
+ onChange?: OnChangeHandler;
32
+ };
33
+ export {};
@@ -0,0 +1,131 @@
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
+ this.roles = [];
17
+ this.onChangeHandler = options.onChange;
18
+ this.activeRecordCardVc = this.ActiveRecordVc();
19
+ }
20
+ ActiveRecordVc() {
21
+ return this.Controller('activeRecordCard', buildActiveRecordCard({
22
+ id: 'roles',
23
+ columnWidths: ['fill'],
24
+ shouldRenderRowDividers: true,
25
+ header: {
26
+ title: 'Roles',
27
+ subtitle: 'Select the roles you want to have fill out this profile.',
28
+ },
29
+ payload: {
30
+ shouldIncludePrivateRoles: true,
31
+ shouldIncludeMetaRoles: false,
32
+ },
33
+ eventName: 'list-roles::v2020_12_25',
34
+ responseKey: 'roles',
35
+ rowTransformer: this.buildRoleRow.bind(this),
36
+ }));
37
+ }
38
+ getCardVc() {
39
+ return this.activeRecordCardVc.getCardVc();
40
+ }
41
+ getActiveRecordCardVc() {
42
+ return this.activeRecordCardVc;
43
+ }
44
+ getListVc() {
45
+ return this.activeRecordCardVc.getListVc();
46
+ }
47
+ getRoles() {
48
+ var _a;
49
+ return (_a = this.roles) !== null && _a !== void 0 ? _a : [];
50
+ }
51
+ setRoles(roles) {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ this.roles = roles;
54
+ assertOptions({ roles }, ['roles'], `The role select card needs roles passed to it to work!`);
55
+ const records = this.activeRecordCardVc.getRecords();
56
+ for (const profileRole of roles) {
57
+ const match = records.find((r) => r.id === profileRole.roleId);
58
+ if (match) {
59
+ const rowVc = this.activeRecordCardVc.getRowVc(match.id);
60
+ yield rowVc.setValue('requirements', this.getRequirementsForRole(match.id));
61
+ }
62
+ }
63
+ this.activeRecordCardVc.triggerRender();
64
+ });
65
+ }
66
+ getIsLoaded() {
67
+ return this.isLoaded;
68
+ }
69
+ buildRoleRow(role) {
70
+ return {
71
+ id: role.id,
72
+ cells: [
73
+ {
74
+ text: {
75
+ content: role.name,
76
+ },
77
+ subText: {
78
+ content: role.description,
79
+ },
80
+ },
81
+ {
82
+ selectInput: {
83
+ name: 'requirements',
84
+ isRequired: true,
85
+ value: this.getRequirementsForRole(role.id),
86
+ onChange: (value) => __awaiter(this, void 0, void 0, function* () {
87
+ var _a;
88
+ yield ((_a = this.onChangeHandler) === null || _a === void 0 ? void 0 : _a.call(this, role.id, value !== null && value !== void 0 ? value : 'skip'));
89
+ this.roles = this.roles.filter((r) => r.roleId !== role.id);
90
+ if (value !== 'skip') {
91
+ this.roles.push({
92
+ roleId: role.id,
93
+ requirements: value,
94
+ });
95
+ }
96
+ }),
97
+ choices: [
98
+ {
99
+ value: 'skip',
100
+ label: 'Skip',
101
+ },
102
+ {
103
+ value: 'optional',
104
+ label: 'Optional',
105
+ },
106
+ {
107
+ value: 'required',
108
+ label: 'Required',
109
+ },
110
+ ],
111
+ },
112
+ },
113
+ ],
114
+ };
115
+ }
116
+ getRequirementsForRole(roleId) {
117
+ var _a;
118
+ return (_a = this.roles.find((r) => r.roleId === roleId)) === null || _a === void 0 ? void 0 : _a.requirements;
119
+ }
120
+ load(options) {
121
+ return __awaiter(this, void 0, void 0, function* () {
122
+ this.activeRecordCardVc.setTarget(options);
123
+ yield this.activeRecordCardVc.load();
124
+ this.isLoaded = true;
125
+ });
126
+ }
127
+ render() {
128
+ return this.activeRecordCardVc.render();
129
+ }
130
+ }
131
+ RoleSelectCardViewController.id = 'role-select-card';
@@ -0,0 +1,2 @@
1
+ export { default as RoleSelectCardViewController } from './adding/RoleSelectCard.vc';
2
+ export * from './types-module';
@@ -0,0 +1,2 @@
1
+ export { default as RoleSelectCardViewController } from './adding/RoleSelectCard.vc.js';
2
+ export * from './types-module.js';
@@ -0,0 +1,14 @@
1
+ import { Card, SkillViewControllerLoadOptions, ViewController } from '@sprucelabs/heartwood-view-controllers';
2
+ import RoleSelectCardViewController, { RoleSelectCardViewControllerOptions } from './adding/RoleSelectCard.vc';
3
+ export { ProfileRole } from './adding/RoleSelectCard.vc';
4
+ export declare type RemoteProfileCard = ViewController<Card> & {
5
+ load?: (options: SkillViewControllerLoadOptions) => Promise<void> | void;
6
+ };
7
+ declare module '@sprucelabs/heartwood-view-controllers/build/types/heartwood.types' {
8
+ interface ViewControllerMap {
9
+ roleSelectCard: RoleSelectCardViewController;
10
+ }
11
+ interface ViewControllerOptionsMap {
12
+ roleSelectCard: RoleSelectCardViewControllerOptions;
13
+ }
14
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -21,4 +21,3 @@ exports.RoleSelectCardViewController = void 0;
21
21
  var RoleSelectCard_vc_1 = require("./adding/RoleSelectCard.vc");
22
22
  Object.defineProperty(exports, "RoleSelectCardViewController", { enumerable: true, get: function () { return __importDefault(RoleSelectCard_vc_1).default; } });
23
23
  __exportStar(require("./types-module"), exports);
24
- //# sourceMappingURL=index-module.js.map
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=types-module.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sprucelabs/spruce-profile-utils",
3
3
  "description": "Useeful utilities",
4
- "version": "1.2.64",
4
+ "version": "1.2.66",
5
5
  "skill": {
6
6
  "namespace": "profile"
7
7
  },