@inizioevoke/veeva-astroclm 1.0.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.
- package/.claude/settings.local.json +10 -0
- package/.claude/skills/evoke-analytics-auditor/SKILL.md +509 -0
- package/.claude/skills/evoke-astro-core/SKILL.md +395 -0
- package/.claude/skills/evoke-page-manager/SKILL.md +75 -0
- package/.claude/skills/evoke-veeva-config-manager/SKILL.md +17 -0
- package/.claude/skills/evoke-veeva-config-manager/create.md +189 -0
- package/.claude/skills/evoke-veeva-config-manager/manage.md +48 -0
- package/.editorconfig +12 -0
- package/.env.development +3 -0
- package/.env.veeva-client +1 -0
- package/.env.veeva-client-training +2 -0
- package/.env.veeva-evoke +4 -0
- package/README.md +43 -0
- package/_contents.yml.example +6 -0
- package/astro.config.ts +36 -0
- package/package.json +40 -0
- package/public/astroclm.png +0 -0
- package/public/favicon.png +0 -0
- package/public/shared/salesforce.js +2586 -0
- package/public/shared/vault.js +2417 -0
- package/src/components/content/readme.md +1 -0
- package/src/components/isi/ISIContent.tsx +137 -0
- package/src/components/isi/_isi.scss +22 -0
- package/src/components/nav/MainNav/MainNav.astro +20 -0
- package/src/components/nav/MainNav/MainNav.tsx +36 -0
- package/src/components/nav/NavList.tsx +66 -0
- package/src/components/ui/Button.astro +19 -0
- package/src/components/ui/Image.astro +36 -0
- package/src/components/ui/IvaConsole/IvaConsole.astro +12 -0
- package/src/components/ui/IvaConsole/IvaConsole.scss +62 -0
- package/src/components/ui/IvaConsole/IvaConsole.ts +144 -0
- package/src/components/ui/Link.astro +39 -0
- package/src/components/ui/Link.tsx +36 -0
- package/src/components/ui/NavLink.astro +46 -0
- package/src/components/ui/NavLink.tsx +41 -0
- package/src/components/ui/VeevaControls/VeevaControls.astro +48 -0
- package/src/components/ui/VeevaControls/VeevaControls.scss +145 -0
- package/src/components/ui/VeevaLink.astro +36 -0
- package/src/data/pages.tsx +50 -0
- package/src/env.d.ts +14 -0
- package/src/lib/client/context.ts +45 -0
- package/src/lib/client/main.ts +54 -0
- package/src/lib/client/readme.md +1 -0
- package/src/lib/client/swipe-nav.ts +35 -0
- package/src/lib/client/utils.ts +58 -0
- package/src/lib/server/readme.md +1 -0
- package/src/lib/server/screen.ts +10 -0
- package/src/middleware.ts.bak +12 -0
- package/src/scss/_mixins.scss +1 -0
- package/src/scss/_variables.scss +6 -0
- package/src/scss/ipads.scss +89 -0
- package/src/shared/img/veeva/veeva-action.png +0 -0
- package/src/shared/img/veeva/veeva-desktop-action.png +0 -0
- package/src/shared/img/veeva/veeva-desktop-navigation.png +0 -0
- package/src/shared/img/veeva/veeva-desktop-next.png +0 -0
- package/src/shared/img/veeva/veeva-desktop-previous.png +0 -0
- package/src/shared/img/veeva/veeva-highlighter.png +0 -0
- package/src/shared/img/veeva/veeva-history-back.png +0 -0
- package/src/shared/img/veeva/veeva-history-forward.png +0 -0
- package/src/shared/img/veeva/veeva-navigation.png +0 -0
- package/src/shared/img/veeva/veeva-reactions.png +0 -0
- package/tasks/page-manager.ts +4 -0
- package/tasks/util.ts +7 -0
- package/tasks/veeva-config.ts +4 -0
- package/tasks/veeva-deploy.ts +21 -0
- package/tsconfig.json +23 -0
- package/veeva-metadata.js +461 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
@use "./variables" as variables;
|
|
2
|
+
@use "sass:list";
|
|
3
|
+
@use "sass:map";
|
|
4
|
+
@use "sass:math";
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* If needed, this can be rendered directly into your layout with
|
|
8
|
+
* import ipadStyles from '../../scss/ipads.scss?inline';
|
|
9
|
+
* <style is:inline set:html={ipadStyles} />
|
|
10
|
+
* render into the <head> for best results
|
|
11
|
+
*/
|
|
12
|
+
body.target-veeva.platform-ipad {
|
|
13
|
+
overflow: hidden;
|
|
14
|
+
.scaling-wrapper {
|
|
15
|
+
transform-origin: left top;
|
|
16
|
+
overflow: hidden;
|
|
17
|
+
}
|
|
18
|
+
// handles scaling for different iPads
|
|
19
|
+
$iPads: (
|
|
20
|
+
( "w": 1024px, "h": 768px ), // ~4:3
|
|
21
|
+
( "w": 1080px, "h": 810px ), // 4:3
|
|
22
|
+
( "w": 1112px, "h": 834px ), // 4:3
|
|
23
|
+
( "w": 1133px, "h": 744px ), // ~3:2
|
|
24
|
+
( "w": 1180px, "h": 820px ), // 59:41 | ~10:7
|
|
25
|
+
( "w": 1194px, "h": 834px ), // ~59:41 | ~10:7
|
|
26
|
+
( "w": 1210px, "h": 834px ), // ~10:7 | ~3:2
|
|
27
|
+
( "w": 1366px, "h": 1024px ), // ~4:3
|
|
28
|
+
( "w": 1376px, "h": 1032px ) // 4:3
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
// Build a single grouped media query for the shared static resets
|
|
32
|
+
$combined-query: "";
|
|
33
|
+
@each $iPad in $iPads {
|
|
34
|
+
$w: map.get($iPad, "w");
|
|
35
|
+
$h: map.get($iPad, "h");
|
|
36
|
+
$scale: math.min(
|
|
37
|
+
math.div($w, variables.$screen-width),
|
|
38
|
+
math.div($h, variables.$screen-height)
|
|
39
|
+
);
|
|
40
|
+
@if $scale != 1 {
|
|
41
|
+
$q: "screen and (min-width: #{$w - 1px}) and (max-width: #{$w + 1px}) and (min-height: #{$h - 1px}) and (max-height: #{$h + 1px})";
|
|
42
|
+
@if $combined-query == "" {
|
|
43
|
+
$combined-query: $q;
|
|
44
|
+
} @else {
|
|
45
|
+
$combined-query: "#{$combined-query}, #{$q}";
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@media #{$combined-query} {
|
|
51
|
+
.body-outer {
|
|
52
|
+
display: block;
|
|
53
|
+
justify-content: unset;
|
|
54
|
+
align-items: unset;
|
|
55
|
+
width: unset;
|
|
56
|
+
height: unset;
|
|
57
|
+
|
|
58
|
+
.scaling-wrapper {
|
|
59
|
+
margin: unset;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Per-device media queries for transform only
|
|
65
|
+
@each $iPad in $iPads {
|
|
66
|
+
$w: map.get($iPad, "w");
|
|
67
|
+
$h: map.get($iPad, "h");
|
|
68
|
+
$scale: math.min(
|
|
69
|
+
math.div($w, variables.$screen-width),
|
|
70
|
+
math.div($h, variables.$screen-height)
|
|
71
|
+
);
|
|
72
|
+
$translateX: math.div(
|
|
73
|
+
math.div($w - variables.$screen-width * $scale, 2),
|
|
74
|
+
$scale
|
|
75
|
+
);
|
|
76
|
+
$translateY: math.div(
|
|
77
|
+
math.div($h - variables.$screen-height * $scale, 2),
|
|
78
|
+
$scale
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
@if $scale != 1 {
|
|
82
|
+
@media screen and (min-width: #{$w - 1px}) and (max-width: #{$w + 1px}) and (min-height: #{$h - 1px}) and (max-height: #{$h + 1px}) {
|
|
83
|
+
.body-outer .scaling-wrapper {
|
|
84
|
+
transform: scale($scale) translate($translateX, $translateY);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/tasks/util.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { loadEnv, parseArgv } from '@inizioevoke/veeva-astroclm-core/lib/server';
|
|
2
|
+
import { deploy } from '@inizioevoke/veeva-astroclm-core/tasks';
|
|
3
|
+
import { root } from './util';
|
|
4
|
+
import VeevaConfig from '../veeva-config';
|
|
5
|
+
|
|
6
|
+
const argv = parseArgv({
|
|
7
|
+
mode: 'string',
|
|
8
|
+
csvOnly: 'boolean'
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
const { VEEVA_ENV, VEEVA_TRAINING } = await loadEnv(argv.mode);
|
|
12
|
+
|
|
13
|
+
await deploy({
|
|
14
|
+
root,
|
|
15
|
+
config: VeevaConfig({
|
|
16
|
+
veevaEnv: VEEVA_ENV,
|
|
17
|
+
isTraining: VEEVA_TRAINING
|
|
18
|
+
}),
|
|
19
|
+
env: VEEVA_ENV,
|
|
20
|
+
csvOnly: argv.csvOnly === true
|
|
21
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "astro/tsconfigs/strict",
|
|
3
|
+
"include": [
|
|
4
|
+
".astro/types.d.ts",
|
|
5
|
+
"**/*"
|
|
6
|
+
],
|
|
7
|
+
"exclude": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"compilerOptions": {
|
|
11
|
+
"jsx": "react-jsx",
|
|
12
|
+
"jsxImportSource": "preact",
|
|
13
|
+
"paths": {
|
|
14
|
+
"@/*": ["./src/*"],
|
|
15
|
+
"@components/*": ["./src/components/*"],
|
|
16
|
+
"@contents/*": ["./src/contents/*"],
|
|
17
|
+
"@data/*": ["./src/data/*"],
|
|
18
|
+
"@layouts/*": ["./src/layouts/*"],
|
|
19
|
+
"@lib/*": ["./src/lib/*"],
|
|
20
|
+
"@shared/*": ["./src/shared/*"]
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Go to Veeva PromoMats and open your presentation in the Chrome.
|
|
3
|
+
* Execute this script in the developer console.
|
|
4
|
+
* Configure the `data` const at top of file
|
|
5
|
+
*/
|
|
6
|
+
(async () => {
|
|
7
|
+
/* ******************************
|
|
8
|
+
*** UPDATE THIS DATA
|
|
9
|
+
****************************** */
|
|
10
|
+
/** @type {VeevaData} */
|
|
11
|
+
const data = {
|
|
12
|
+
/* Is this a training presentation? Only necessary if using { training, default } fields in meta. */
|
|
13
|
+
isTraining: false,
|
|
14
|
+
skipPresentation: false,
|
|
15
|
+
slideStartIndex: null,
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
/* Data fields */
|
|
19
|
+
meta: {
|
|
20
|
+
// 'textarea[name="name"]': (val) => { return val.replace(/^AAAAA/, 'BBBBB'); },
|
|
21
|
+
/* Gilead Key Dates > Expiration Date */
|
|
22
|
+
'input[name="expirationDate"]': {
|
|
23
|
+
'training': '07/27/2026',
|
|
24
|
+
'default': '06/01/2028'
|
|
25
|
+
},
|
|
26
|
+
/* Gilead US CRM Sharing Settings
|
|
27
|
+
* Negate by prefixing with ! */
|
|
28
|
+
crm_sharing_settings: [
|
|
29
|
+
'US MM',
|
|
30
|
+
'US Sales OTS',
|
|
31
|
+
'US Sales ONC'
|
|
32
|
+
]
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
/* Set the CRM Product */
|
|
36
|
+
// crmProduct: 'TRODELVY',
|
|
37
|
+
|
|
38
|
+
/* Set the approved material */
|
|
39
|
+
approvedMaterial: {
|
|
40
|
+
// remove any other material that does not match a code/version'. Default true
|
|
41
|
+
remove: true,
|
|
42
|
+
// adding Approved Material only works if the document is a "Favorite"
|
|
43
|
+
docs: [
|
|
44
|
+
'US-XXXX-0000',
|
|
45
|
+
'US-XXXX-1111'
|
|
46
|
+
]
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
/* Set the status */
|
|
50
|
+
status: "stage"
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
const SAVE_SLEEP_TIME = 5000; // If veeva is running slow increase this value
|
|
55
|
+
|
|
56
|
+
/* *******************************
|
|
57
|
+
* DO NOT EDIT ANYTHING BELOW HERE
|
|
58
|
+
* ******************************* */
|
|
59
|
+
|
|
60
|
+
const start = Date.now();
|
|
61
|
+
const BTN_EDIT = 'button.vv-edit-field-button-icon';
|
|
62
|
+
const BTN_SAVE = 'a.docInfoSaveButton';
|
|
63
|
+
const BTN_CANCEL = 'a.docInfoCancelButton';
|
|
64
|
+
|
|
65
|
+
function formatTime(ms) {
|
|
66
|
+
const mins = Math.floor(ms / 1000 / 60);
|
|
67
|
+
const secs = Math.floor(ms / 1000) % 60;
|
|
68
|
+
return `${mins}m ${secs}s`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function sleep(timeout) {
|
|
72
|
+
return new Promise((resolve) => {
|
|
73
|
+
setTimeout(resolve, timeout);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function getElement(selector, container = document) {
|
|
78
|
+
return new Promise((resolve) => {
|
|
79
|
+
if (selector instanceof HTMLElement) {
|
|
80
|
+
resolve(selector);
|
|
81
|
+
} else {
|
|
82
|
+
const el = container.querySelector(selector);
|
|
83
|
+
if (el) {
|
|
84
|
+
resolve(el);
|
|
85
|
+
} else {
|
|
86
|
+
setTimeout(() => {
|
|
87
|
+
getElement(selector, container).then((el) => {
|
|
88
|
+
resolve(el);
|
|
89
|
+
});
|
|
90
|
+
}, 500);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async function clickBtn(selector, container = document) {
|
|
97
|
+
(await getElement(selector, container)).click();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function __updateMetaFields() {
|
|
101
|
+
let forceChange = false;
|
|
102
|
+
let crm_sharing_settings = null;
|
|
103
|
+
if (data.meta && Object.keys(data.meta).length > 0) {
|
|
104
|
+
Object.keys(data.meta).forEach((key) => {
|
|
105
|
+
if (key === 'crm_sharing_settings') {
|
|
106
|
+
crm_sharing_settings = data.meta[key];
|
|
107
|
+
} else {
|
|
108
|
+
const element = document.querySelector(key);
|
|
109
|
+
if (element) {
|
|
110
|
+
switch (element.tagName.toLowerCase()) {
|
|
111
|
+
case 'input': {
|
|
112
|
+
switch (element.getAttribute('type')) {
|
|
113
|
+
case 'radio':
|
|
114
|
+
element.click();
|
|
115
|
+
break;
|
|
116
|
+
default: {
|
|
117
|
+
let value = null;
|
|
118
|
+
if (typeof data.meta[key] == 'function') {
|
|
119
|
+
value = data.meta[key](element.value);
|
|
120
|
+
} else {
|
|
121
|
+
value = typeof data.meta[key] != 'string' ? data.meta[key][data.isTraining ?? false ? 'training' : 'default'] : data.meta[key];
|
|
122
|
+
}
|
|
123
|
+
if (value !== null && element.value != value) {
|
|
124
|
+
element.value = value;
|
|
125
|
+
forceChange = true;
|
|
126
|
+
}
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
case 'textarea': {
|
|
133
|
+
let value = null;
|
|
134
|
+
if (typeof data.meta[key] == 'function') {
|
|
135
|
+
value = data.meta[key](element.value);
|
|
136
|
+
} else {
|
|
137
|
+
value = typeof data.meta[key] != 'string' ? data.meta[key][data.isTraining ?? false ? 'training' : 'default'] : data.meta[key];
|
|
138
|
+
}
|
|
139
|
+
if (value && element.value != value) {
|
|
140
|
+
element.value = value;
|
|
141
|
+
forceChange = true;
|
|
142
|
+
}
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
default: {
|
|
146
|
+
console.log(`ERROR: ${key} not handled!`);
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
} else {
|
|
151
|
+
console.log(`ERROR: ${key} not found!`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
__updateCrmSharingSettings(crm_sharing_settings);
|
|
157
|
+
|
|
158
|
+
// return forceChange;
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function __updateCrmSharingSettings(settings) {
|
|
163
|
+
const shareSettings = document.querySelector('h3[title="US CRM Sharing Settings"]');
|
|
164
|
+
if (shareSettings) {
|
|
165
|
+
const section = shareSettings.parentNode;
|
|
166
|
+
|
|
167
|
+
if (settings) {
|
|
168
|
+
const teams = [...section.querySelectorAll('.doc_info_property_label .propertyLabelSpan')];
|
|
169
|
+
if (!Array.isArray(settings)) {
|
|
170
|
+
settings = data.isTraining ? settings['training'] : settings['default'];
|
|
171
|
+
}
|
|
172
|
+
// set all to No
|
|
173
|
+
teams.forEach((team) => {
|
|
174
|
+
team.closest('.inputContainer').querySelector(`input[type="radio"][value="false"]`).click();
|
|
175
|
+
});
|
|
176
|
+
// set configured to Yes
|
|
177
|
+
settings.forEach((key) => {
|
|
178
|
+
const team = teams.filter(t => t.textContent === key).pop();
|
|
179
|
+
if (team) {
|
|
180
|
+
team.closest('.inputContainer').querySelector(`input[type="radio"][value="true"]`).click();
|
|
181
|
+
} else {
|
|
182
|
+
console.log(`Could not select sharing setting: ${typeof key == 'string' ? key : JSON.stringify(key)}`);
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// make sure that all CRM Sharing Settings have a value
|
|
188
|
+
const radioForms = section.querySelectorAll('.vv_radio_form');
|
|
189
|
+
radioForms.forEach((form) => {
|
|
190
|
+
const hasChecked = [...form.querySelectorAll('input[type="radio"]')].some((el) => el.checked);
|
|
191
|
+
if (!hasChecked) {
|
|
192
|
+
form.querySelector('input[type="radio"][value="false"]').click();
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
async function selectCrmProduct() {
|
|
199
|
+
if (data.crmProduct && document.querySelector('[name="crmProduct_b"] input').value !== data.crmProduct) {
|
|
200
|
+
await clickBtn('[name="crmProduct_b"] button');
|
|
201
|
+
await sleep(2000);
|
|
202
|
+
let found = false;
|
|
203
|
+
while (!found) {
|
|
204
|
+
const productLabel = [...document.querySelectorAll('.vv-vof-lookup-table-name-label')].filter((el) => { return new RegExp(data.crmProduct,'i').test(el.innerText); })[0]
|
|
205
|
+
if (productLabel) {
|
|
206
|
+
found = true;
|
|
207
|
+
productLabel.parentElement.parentElement.parentElement.querySelector('input[type="radio"]').click();
|
|
208
|
+
await sleep(1000);
|
|
209
|
+
} else {
|
|
210
|
+
await clickBtn('.vv-bp-advance-search-dialog-pagination button[title="Next Page"]')
|
|
211
|
+
await sleep(1000);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
await clickBtn('.vv-bp-advance-search-dialog footer button');
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
async function updateMeta() {
|
|
219
|
+
// edit the meta data
|
|
220
|
+
if (data.meta || data.crmProduct) {
|
|
221
|
+
await clickBtn(BTN_EDIT);
|
|
222
|
+
await getElement(BTN_SAVE);
|
|
223
|
+
const forceChange = __updateMetaFields(data);
|
|
224
|
+
await selectCrmProduct();
|
|
225
|
+
const saveBtn = await getElement(BTN_SAVE);
|
|
226
|
+
if (!saveBtn.classList.contains('vv_disabled')) {
|
|
227
|
+
await clickBtn(BTN_SAVE);
|
|
228
|
+
} else {
|
|
229
|
+
// make sure the save button is enabled for text changes
|
|
230
|
+
if (forceChange) {
|
|
231
|
+
const pubYes = document.querySelector('#clmContent_bYES');
|
|
232
|
+
const pubNo = document.querySelector('#clmContent_bNO');
|
|
233
|
+
if (pubYes.checked) {
|
|
234
|
+
pubNo.click();
|
|
235
|
+
pubYes.click();
|
|
236
|
+
} else {
|
|
237
|
+
pubYes.click();
|
|
238
|
+
pubNo.click();
|
|
239
|
+
}
|
|
240
|
+
await new Promise((resolve) => {
|
|
241
|
+
const wait = async () => {
|
|
242
|
+
if (!saveBtn.classList.contains('vv_disabled')) {
|
|
243
|
+
await clickBtn(BTN_SAVE);
|
|
244
|
+
resolve();
|
|
245
|
+
} else {
|
|
246
|
+
requestAnimationFrame(wait);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
wait();
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
// if (!saveBtn.classList.contains('vv_disabled')) {
|
|
253
|
+
// await clickBtn(BTN_SAVE);
|
|
254
|
+
// } else {
|
|
255
|
+
// await clickBtn(BTN_CANCEL);
|
|
256
|
+
// }
|
|
257
|
+
} else {
|
|
258
|
+
await clickBtn(BTN_CANCEL);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
await getElement(BTN_EDIT);
|
|
262
|
+
await sleep(SAVE_SLEEP_TIME);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (data.approvedMaterial) {
|
|
266
|
+
await clickBtn('[data-testid="doc_info_relationships__sys"]');
|
|
267
|
+
await sleep(500);
|
|
268
|
+
await clickBtn('h3[title="Related Approved Material"]');
|
|
269
|
+
await sleep(1000);
|
|
270
|
+
const addedDocs = [...document.querySelector('h3[title="Related Approved Material"]').parentElement.querySelectorAll('.doc_info_section_body > .relatedDoc')];
|
|
271
|
+
|
|
272
|
+
const docsToRelate = addedDocs.length === 0 ? data.approvedMaterial.docs : [];
|
|
273
|
+
if (docsToRelate.length === 0) {
|
|
274
|
+
const relatedDocs = addedDocs
|
|
275
|
+
.map((doc) => {
|
|
276
|
+
const [ major, minor ] = doc.querySelector('.docVersion').innerText.trim().match(/\(v(\d+\.\d+)\)/)[1].split('.').map(v => parseInt(v));;
|
|
277
|
+
return {
|
|
278
|
+
code: doc.querySelector('.docNumber').innerText.trim(),
|
|
279
|
+
version: { major, minor },
|
|
280
|
+
element: doc
|
|
281
|
+
};
|
|
282
|
+
});
|
|
283
|
+
const latestVersions = {};
|
|
284
|
+
relatedDocs.forEach((doc) => {
|
|
285
|
+
if (!latestVersions[doc.code]) {
|
|
286
|
+
latestVersions[doc.code] = {...doc.version};
|
|
287
|
+
} else {
|
|
288
|
+
const cur = latestVersions[doc.code];
|
|
289
|
+
if (doc.version.major > cur.major || (doc.version.major === cur.major && doc.version.minor > cur.minor)) {
|
|
290
|
+
latestVersions[doc.code] = {...doc.version};
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
relatedDocs.forEach((doc) => {
|
|
295
|
+
doc.isLatest = doc.version.major === latestVersions[doc.code].major && doc.version.minor === latestVersions[doc.code].minor;
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
const docsToRemove = [];
|
|
299
|
+
// find any doc that doesn't match a metadata code or isn't the latest and flag it for removal
|
|
300
|
+
for (const relatedDoc of relatedDocs) {
|
|
301
|
+
if (data.approvedMaterial.docs.indexOf(relatedDoc.code) === -1 || !relatedDoc.isLatest) {
|
|
302
|
+
docsToRemove.push(relatedDoc);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
if (docsToRemove.length > 0 && data.approvedMaterial.remove !== false) {
|
|
306
|
+
for (const doc of docsToRemove) {
|
|
307
|
+
console.log(`Removing related document: ${doc.code} (v${doc.version.major}.${doc.version.minor})`);
|
|
308
|
+
await clickBtn(doc.element.querySelector('a.deleteRelation'));
|
|
309
|
+
await sleep(500);
|
|
310
|
+
await clickBtn('.vv_alert_dialog a.vv_button.ok');
|
|
311
|
+
await sleep(1000);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// filter docs that were already removed
|
|
316
|
+
const remainingDocs = relatedDocs.filter((d) => {
|
|
317
|
+
return !docsToRemove.find((r) => {
|
|
318
|
+
return r.code === d.code && r.version.major === d.version.major && r.version.minor === d.version.minor;
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
for (const code of data.approvedMaterial.docs) {
|
|
323
|
+
if (!remainingDocs.find(r => r.code === code)) {
|
|
324
|
+
docsToRelate.push(code);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
if (docsToRelate.length > 0) {
|
|
330
|
+
await clickBtn('a.add-relatedApprovedMaterial');
|
|
331
|
+
await sleep(2000);
|
|
332
|
+
await clickBtn('.vv-related-document-lookup .vv-view-picker button');
|
|
333
|
+
await sleep(500);
|
|
334
|
+
await clickBtn('ul[role="listbox"] li[role="option"][data-value="fav"]');
|
|
335
|
+
await sleep(2000);
|
|
336
|
+
for (const code of docsToRelate) {
|
|
337
|
+
const approvedItem = [...document.querySelectorAll('.vv-related-document-lookup .vv-search-results > ul > li')].find((li) => {
|
|
338
|
+
return li.querySelector('.vv-search-result-docnumber > span > span').innerText.trim() === code;
|
|
339
|
+
});
|
|
340
|
+
if (approvedItem) {
|
|
341
|
+
console.log(`Found approved material: ${code}`);
|
|
342
|
+
const cb = approvedItem.querySelector('input[type="checkbox"]');
|
|
343
|
+
if (!cb.checked) {
|
|
344
|
+
cb.click();
|
|
345
|
+
await sleep(1000);
|
|
346
|
+
}
|
|
347
|
+
} else {
|
|
348
|
+
console.log(`Did not find approved material: ${code}. Make sure it is a favorite!`);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
await clickBtn('.vv-related-document-lookup footer button');
|
|
352
|
+
} else {
|
|
353
|
+
console.log('All approved material related');
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
async function setStatus() {
|
|
359
|
+
if (data.status) {
|
|
360
|
+
const lifeCycleBtn = await getElement('header .vv-doc-state-badge .vv-picker-badge button');
|
|
361
|
+
if (lifeCycleBtn.innerText.toLowerCase() !== (data.status ? 'staged' : 'draft')) {
|
|
362
|
+
await clickBtn(lifeCycleBtn);
|
|
363
|
+
await sleep(250);
|
|
364
|
+
let stageBtn = document.querySelector(`[id$="dynamicAction:${data.status}"]`);
|
|
365
|
+
while (!stageBtn) {
|
|
366
|
+
await sleep(250);
|
|
367
|
+
stageBtn = document.querySelector(`[id$="dynamicAction:${data.status}"]`);
|
|
368
|
+
}
|
|
369
|
+
await clickBtn(stageBtn);
|
|
370
|
+
await sleep(500);
|
|
371
|
+
await clickBtn('[role="dialog"] a.save');
|
|
372
|
+
await sleep(SAVE_SLEEP_TIME);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
async function openPresAllDocuments() {
|
|
378
|
+
await clickBtn('.vv-more-actions-button button');
|
|
379
|
+
await clickBtn('[id$="ViewAllDocuments"]');
|
|
380
|
+
await sleep(SAVE_SLEEP_TIME);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
async function updateSharedResource() {
|
|
384
|
+
// await sleep(2000);
|
|
385
|
+
const relationshipsBtn = await getElement('[data-target-key="doc_info_relationships__sys"]');
|
|
386
|
+
if (!relationshipsBtn.classList.contains('document-panel-tab-selected')) {
|
|
387
|
+
await clickBtn(relationshipsBtn);
|
|
388
|
+
}
|
|
389
|
+
const header = await getElement('.section-related_shared_resource__pm');
|
|
390
|
+
if (header) {
|
|
391
|
+
await clickBtn(header);
|
|
392
|
+
const sharedResource = await getElement('.doc_info_section_body a', header.parentElement);
|
|
393
|
+
if (sharedResource) {
|
|
394
|
+
await clickBtn(sharedResource);
|
|
395
|
+
await sleep(SAVE_SLEEP_TIME);
|
|
396
|
+
await updateMeta(data);
|
|
397
|
+
await setStatus(data);
|
|
398
|
+
await sleep(SAVE_SLEEP_TIME);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
if (data.skipPresentation !== true) {
|
|
404
|
+
console.log('Updating presentation');
|
|
405
|
+
console.log(data);
|
|
406
|
+
await updateMeta();
|
|
407
|
+
}
|
|
408
|
+
if (typeof data.slideStartIndex != 'number') {
|
|
409
|
+
await openPresAllDocuments();
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
const slideBtns = [...document.querySelectorAll('#mdvNav a')];
|
|
413
|
+
console.log(`Updating ${slideBtns.length} slides`);
|
|
414
|
+
const loopStart = Date.now();
|
|
415
|
+
for (i=(data.slideStartIndex ?? 0); i<slideBtns.length; i++) {
|
|
416
|
+
console.log(`Slide ${i+1}`);
|
|
417
|
+
if (i > 0) {
|
|
418
|
+
await clickBtn(slideBtns[i]);
|
|
419
|
+
await sleep(SAVE_SLEEP_TIME);
|
|
420
|
+
}
|
|
421
|
+
await updateMeta();
|
|
422
|
+
await setStatus();
|
|
423
|
+
const processed = i - (data.slideStartIndex ?? 0) + 1;
|
|
424
|
+
const avgPerSlide = (Date.now() - loopStart) / processed;
|
|
425
|
+
const slidesLeft = (slideBtns.length - 1 - i) + 1; // +1 for shared resource
|
|
426
|
+
console.log(`Time remaining: ${formatTime(avgPerSlide * slidesLeft)}`);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
console.log('Updating the shared resource');
|
|
430
|
+
await updateSharedResource();
|
|
431
|
+
|
|
432
|
+
await clickBtn('a.prev_page');
|
|
433
|
+
await sleep(SAVE_SLEEP_TIME);
|
|
434
|
+
await clickBtn('a.prev_page');
|
|
435
|
+
console.log(`Update complete! Run time ${formatTime(Date.now() - start)}`);
|
|
436
|
+
|
|
437
|
+
})();
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
/* TYPE DEFINITIONS */
|
|
441
|
+
/**
|
|
442
|
+
* @typedef {object} VeevaMetadata
|
|
443
|
+
* @prop {string[]} crm_sharing_settings
|
|
444
|
+
* @prop {Object.<string, any>} [key]
|
|
445
|
+
*/
|
|
446
|
+
/**
|
|
447
|
+
* @typedef {object} VeevaApprovedMaterial
|
|
448
|
+
* @prop {string} code
|
|
449
|
+
* @prop {string} [version]
|
|
450
|
+
* @prop {boolean} [remove]
|
|
451
|
+
*/
|
|
452
|
+
/**
|
|
453
|
+
* @typedef {object} VeevaData
|
|
454
|
+
* @prop {boolean} isTraining
|
|
455
|
+
* @prop {boolean} skipPresentation
|
|
456
|
+
* @prop {number} slideStartIndex
|
|
457
|
+
* @prop {VeevaMetadata} meta
|
|
458
|
+
* @prop {string} crmProduct
|
|
459
|
+
* @prop {VeevaApprovedMaterial} approvedMaterial
|
|
460
|
+
* @prop {'draft'|'stage'} status
|
|
461
|
+
*/
|