farseer-cli 1.24.0 → 1.26.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/README.md +1 -1
- package/dist/commands/dashboards.js +2 -0
- package/dist/commands/dashboards.js.map +1 -1
- package/dist/commands/login.js +18 -7
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/logout.js +28 -12
- package/dist/commands/logout.js.map +1 -1
- package/dist/commands/run.js +2 -3
- package/dist/commands/run.js.map +1 -1
- package/dist/commands/sheets.js +5 -3
- package/dist/commands/sheets.js.map +1 -1
- package/dist/commands/whoami.js +12 -5
- package/dist/commands/whoami.js.map +1 -1
- package/dist/mcp/tools/authTools.js +2 -1
- package/dist/mcp/tools/authTools.js.map +1 -1
- package/dist/mcp/tools/dashboardTools.js +3 -1
- package/dist/mcp/tools/dashboardTools.js.map +1 -1
- package/dist/mcp/tools/runTools.js +2 -3
- package/dist/mcp/tools/runTools.js.map +1 -1
- package/dist/mcp/utils/helpers.js +8 -6
- package/dist/mcp/utils/helpers.js.map +2 -2
- package/dist/mcp/utils/session.js +6 -2
- package/dist/mcp/utils/session.js.map +1 -1
- package/dist/operations/dashboards.js +1 -1
- package/dist/operations/dashboards.js.map +1 -1
- package/dist/pipeline/generated-reference.json +8 -8
- package/dist/services/codefirst/layoutReadback.js +95 -0
- package/dist/services/codefirst/layoutReadback.js.map +2 -2
- package/dist/services/configService.js +33 -18
- package/dist/services/configService.js.map +1 -1
- package/dist/services/credentials.js +26 -11
- package/dist/services/credentials.js.map +1 -1
- package/dist/services/farseerService.js +34 -32
- package/dist/services/farseerService.js.map +1 -1
- package/dist/services/keycloak.js +44 -0
- package/dist/services/keycloak.js.map +6 -0
- package/dist/services/preflight.js +1 -2
- package/dist/services/preflight.js.map +1 -1
- package/dist/services/realms.js +67 -15
- package/dist/services/realms.js.map +1 -1
- package/dist/utils/serverUrl.js +42 -0
- package/dist/utils/serverUrl.js.map +6 -0
- package/docs/pipeline-reference.md +13 -3
- package/package.json +2 -2
- package/skills/farseer-build-model/SKILL.md +1 -1
- package/skills/farseer-code-tiles/SKILL.md +153 -0
- package/skills/farseer-code-tiles/anti-patterns.md +183 -0
- package/skills/farseer-code-tiles/api.md +237 -0
- package/skills/farseer-code-tiles/check-tile.mjs +521 -0
- package/skills/farseer-code-tiles/design.md +159 -0
- package/skills/farseer-code-tiles/echarts-look.md +110 -0
- package/skills/farseer-code-tiles/examples/board-deck.js +695 -0
- package/skills/farseer-code-tiles/examples/data-checks.js +475 -0
- package/skills/farseer-code-tiles/examples/kpi-cards.js +374 -0
- package/skills/farseer-code-tiles/examples/map-countries.js +377 -0
- package/skills/farseer-code-tiles/examples/month-plan.js +443 -0
- package/skills/farseer-code-tiles/examples/new-location.js +581 -0
- package/skills/farseer-code-tiles/examples/open-forecast.js +598 -0
- package/skills/farseer-code-tiles/examples/pl-sankey.js +402 -0
- package/skills/farseer-code-tiles/examples/ranked-bars.js +337 -0
- package/skills/farseer-code-tiles/examples/request-form.js +464 -0
- package/skills/farseer-code-tiles/farseer-table.md +98 -0
- package/skills/farseer-code-tiles/known-mistakes.md +178 -0
- package/skills/farseer-code-tiles/maps/europe.geo.json +1 -0
- package/skills/farseer-code-tiles/maps/pick-map.mjs +59 -0
- package/skills/farseer-code-tiles/maps/world.geo.json +1 -0
- package/skills/farseer-dashboards/SKILL.md +3 -2
- package/skills/farseer-dashboards/check.md +3 -2
- package/skills/farseer-dashboards/measures.md +3 -1
- package/skills/farseer-dashboards/reporting-period.md +1 -1
- package/skills/farseer-modify-model/SKILL.md +1 -1
- package/skills/farseer-modify-model/model-validation-pattern.md +3 -3
- package/skills/farseer-optimize-model/SKILL.md +9 -1
- package/skills/farseer-pnl/SKILL.md +3 -3
- package/skills/pipeline-authoring/SKILL.md +2 -2
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
// A forecast planner: one cost centre, account and company of the department picked in the filter bar, the twelve
|
|
2
|
+
// months of FC 8+4 beside Budget 2026, the open months as inputs. "Save the forecast" writes each changed month's
|
|
3
|
+
// cell into the model; the closed months are actuals and stay as they are.
|
|
4
|
+
// Tile size: w18 h17; w14 h19 when narrow.
|
|
5
|
+
export default function (ctx) {
|
|
6
|
+
// readTable: a table of numbers from the model, in the shape ctx.charts.farseer draws
|
|
7
|
+
// ({ columns: [{ label, numberFormat }], rows: [{ label, cells: [{ value }] }] }). Call it in the body.
|
|
8
|
+
// rows: { table: 'Entity' } every member of a table, listed live by name
|
|
9
|
+
// rows: { table, includeDashboardFilters: true } the members the filter bar leaves, even when the numbers ignore it
|
|
10
|
+
// rows: { table: 'Months', members: ['M1', …] } the members named here, in this order
|
|
11
|
+
// rows: [{ label, formula, numberFormat }] one line per formula (a P&L)
|
|
12
|
+
// no rows one row, labelled '', for KPIs
|
|
13
|
+
// columns: [{ label, formula, numberFormat }] with member rows, [{ label, filter }] with formula lines
|
|
14
|
+
// Member rows and every number follow the filter bar and timeline, unless the spec turns them off.
|
|
15
|
+
const quote = (name) => `"${String(name).replace(/(["\\])/g, '\\$1')}"`;
|
|
16
|
+
// a table's members from a DTABLE answer, by name, without its NULL member
|
|
17
|
+
const namesOf = (answer) => (answer?.value ?? []).map(String).filter((name) => !name.startsWith('NULL ('));
|
|
18
|
+
function withFilter(formula, filter) {
|
|
19
|
+
let out = '', depth = [], quoted = false;
|
|
20
|
+
for (let i = 0; i < formula.length; i++) {
|
|
21
|
+
const c = formula[i];
|
|
22
|
+
if (c === '"' && formula[i - 1] !== '\\') quoted = !quoted;
|
|
23
|
+
if (!quoted && c === '(') depth.push(/sum\s*$/i.test(formula.slice(0, i)));
|
|
24
|
+
if (!quoted && c === ')' && depth.pop()) out += `, ${filter}`;
|
|
25
|
+
out += c;
|
|
26
|
+
}
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
29
|
+
function readTable(spec) {
|
|
30
|
+
// includeDashboardFilters: false / includeDashboardTimeline: false in the spec leave one out (say so on the tile)
|
|
31
|
+
const options = { includeDashboardFilters: spec.includeDashboardFilters !== false, includeDashboardTimeline: spec.includeDashboardTimeline !== false };
|
|
32
|
+
const { columns } = spec;
|
|
33
|
+
const rows = spec.rows ?? [{ label: '' }];
|
|
34
|
+
const memberRows = !Array.isArray(rows);
|
|
35
|
+
const listOptions = { ...options, ...(memberRows && rows.includeDashboardFilters !== undefined ? { includeDashboardFilters: rows.includeDashboardFilters } : {}) };
|
|
36
|
+
const list = memberRows && !rows.members ? ctx.query([{ type: 'DTABLE', table: rows.table }], listOptions) : null;
|
|
37
|
+
let names = memberRows ? rows.members ?? null : null;
|
|
38
|
+
let listed = null;
|
|
39
|
+
let values = null;
|
|
40
|
+
const open = () => {
|
|
41
|
+
values?.close();
|
|
42
|
+
const formulas = memberRows
|
|
43
|
+
? names.flatMap((name) => columns.map((c) => withFilter(c.formula, `${quote(rows.table)}>${quote(name)}`)))
|
|
44
|
+
: rows.flatMap((r) => columns.map((c) => (r.formula ? withFilter(r.formula, c.filter) : c.formula)));
|
|
45
|
+
values = formulas.length ? ctx.query(formulas.map((formula) => ({ type: 'VARIABLE', formula })), options) : null;
|
|
46
|
+
};
|
|
47
|
+
if (!list) open();
|
|
48
|
+
const refresh = () => {
|
|
49
|
+
if (list.loading && !list.current.length) return;
|
|
50
|
+
const now = namesOf(list.current[0]);
|
|
51
|
+
const key = now.join('\u0001');
|
|
52
|
+
if (key !== listed) {
|
|
53
|
+
listed = key;
|
|
54
|
+
names = now;
|
|
55
|
+
open();
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
return {
|
|
59
|
+
get loading() {
|
|
60
|
+
if (list) refresh();
|
|
61
|
+
return (list?.loading ?? false) || (values?.loading ?? false);
|
|
62
|
+
},
|
|
63
|
+
get error() {
|
|
64
|
+
return list?.error ?? values?.error ?? null;
|
|
65
|
+
},
|
|
66
|
+
get current() {
|
|
67
|
+
if (list) refresh();
|
|
68
|
+
const cells = values?.current ?? [];
|
|
69
|
+
const labels = memberRows ? names ?? [] : rows.map((r) => r.label);
|
|
70
|
+
return {
|
|
71
|
+
columns: columns.map((c) => ({ label: c.label, numberFormat: c.numberFormat ?? (memberRows ? null : rows[0]?.numberFormat) ?? null })),
|
|
72
|
+
rows: labels.map((label, j) => ({
|
|
73
|
+
label,
|
|
74
|
+
numberFormat: memberRows ? null : rows[j].numberFormat ?? null,
|
|
75
|
+
cells: columns.map((_, i) => ({ value: cells[j * columns.length + i]?.value ?? null })),
|
|
76
|
+
})),
|
|
77
|
+
};
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
// picks(['Entity', 'Year to date']): what the filter bar picked on these tables, for a title or a form.
|
|
82
|
+
// current.Entity is { members: ['Acme Croatia'], all: false }; all is true when the bar doesn't narrow that table.
|
|
83
|
+
function picks(tables) {
|
|
84
|
+
const picked = ctx.query(tables.map((table) => ({ type: 'DTABLE', table })));
|
|
85
|
+
const every = ctx.query(tables.map((table) => ({ type: 'DTABLE', table })), { includeDashboardFilters: false, includeDashboardTimeline: false });
|
|
86
|
+
return {
|
|
87
|
+
get loading() {
|
|
88
|
+
return picked.loading || every.loading;
|
|
89
|
+
},
|
|
90
|
+
get error() {
|
|
91
|
+
return picked.error ?? every.error ?? null;
|
|
92
|
+
},
|
|
93
|
+
get current() {
|
|
94
|
+
return Object.fromEntries(tables.map((table, i) => {
|
|
95
|
+
const members = namesOf(picked.current[i]);
|
|
96
|
+
return [table, { members, all: members.length === namesOf(every.current[i]).length }];
|
|
97
|
+
}));
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
// what the filter bar picked, for the title and the form
|
|
102
|
+
const bar = picks(['Entity', 'Year to date', 'Department']);
|
|
103
|
+
// --- The Farseer look (echarts-look.md, design.md): the same block in every tile ---
|
|
104
|
+
// AC: the dashboards' AC colour (SKILL.md section 2, The AC colour): #323232, or the company's
|
|
105
|
+
// darkest brand colour when it is dark enough, never an example's. AC_LIGHT is its PY tint.
|
|
106
|
+
// Everything else below is derived from them, so nothing else needs changing.
|
|
107
|
+
const AC = '#323232';
|
|
108
|
+
const AC_LIGHT = '#A6A6A6';
|
|
109
|
+
// mixes a colour with white: share 1 is the colour itself, 0 is white
|
|
110
|
+
function tint(hex, share) {
|
|
111
|
+
const n = parseInt(hex.slice(1), 16);
|
|
112
|
+
const mix = (c) => Math.round(c * share + 255 * (1 - share)).toString(16).padStart(2, '0');
|
|
113
|
+
return `#${mix(n >> 16)}${mix((n >> 8) & 255)}${mix(n & 255)}`.toUpperCase();
|
|
114
|
+
}
|
|
115
|
+
// a colour with almost no hue (graphite, grey): its ramp would turn a map grey, so magnitude takes Farseer blue
|
|
116
|
+
const isGrey = (hex) => { const n = parseInt(hex.slice(1), 16); const c = [n >> 16, (n >> 8) & 255, n & 255]; return Math.max(...c) - Math.min(...c) < 24; };
|
|
117
|
+
const PALETTE = [AC, '#ED7D16', '#1BB5D7', '#8A2FE5', '#BFA812', '#E52FCD']; // identity: AC first, then distinct hues
|
|
118
|
+
const FILL = [AC_LIGHT, '#F5B87F', '#82D6E9', '#BF8DF1', '#DCCF7D', '#F18DE4']; // the light step, for large areas
|
|
119
|
+
// magnitude (maps, heatmaps), light to dark: steps of AC, or Farseer blue when AC is a grey
|
|
120
|
+
const RAMP = isGrey(AC) ? ['#81A9FF', '#457DFF', '#0D4BC2', '#043288'] : [0.45, 0.65, 0.8, 1].map((s) => tint(AC, s));
|
|
121
|
+
// light tints of AC for large areas that need ink text (treemap groups), clearly apart from each other
|
|
122
|
+
// (from Farseer blue when AC is a grey, as the ramp: grey tints would make a grey block)
|
|
123
|
+
const TINTS = [0.52, 0.37, 0.24, 0.11].map((s) => tint(isGrey(AC) ? '#043288' : AC, s));
|
|
124
|
+
const TRACK = tint(AC, 0.12); // the unfilled part of a gauge
|
|
125
|
+
const PRIMARY = '#1A66FF'; // Farseer's own primary button, not a data colour
|
|
126
|
+
const GOOD = '#0CB955';
|
|
127
|
+
const BAD = '#E21E09';
|
|
128
|
+
const INK = () => ctx.theme.tokens?.text ?? '#020810';
|
|
129
|
+
const MUTED = () => ctx.theme.tokens?.muted ?? '#687C95';
|
|
130
|
+
const LINE = () => ctx.theme.tokens?.border ?? '#E6EBF2';
|
|
131
|
+
const SURFACE = () => ctx.theme.tokens?.background ?? '#FFFFFF';
|
|
132
|
+
const FONT = 'Inter, system-ui, sans-serif';
|
|
133
|
+
let drawnOnce = false;
|
|
134
|
+
// draws one echarts chart in the look; the first chart that draws ends the entrance animation for the rest
|
|
135
|
+
function drawChart(element, option) {
|
|
136
|
+
ctx.charts.echarts(element, option);
|
|
137
|
+
drawnOnce = true;
|
|
138
|
+
}
|
|
139
|
+
// the chart tile's look, measured from it: square bars, 12 px ink labels with a surface-coloured halo, an ink
|
|
140
|
+
// category axis with ticks, no value axis or gridlines, the legend at the bottom, its tooltip and margins
|
|
141
|
+
const LABEL = { show: true, fontFamily: FONT, fontSize: 12, color: INK(), textBorderColor: SURFACE(), textBorderWidth: 4 };
|
|
142
|
+
function look() {
|
|
143
|
+
return {
|
|
144
|
+
animation: !drawnOnce,
|
|
145
|
+
animationDuration: 500,
|
|
146
|
+
textStyle: { fontFamily: FONT, fontSize: 12, color: INK() },
|
|
147
|
+
grid: { left: 10, right: 10, top: 20, bottom: 10, containLabel: true },
|
|
148
|
+
legend: { bottom: 0, textStyle: { fontFamily: FONT, color: INK() } },
|
|
149
|
+
tooltip: {
|
|
150
|
+
trigger: 'item', confine: true, backgroundColor: SURFACE(), borderColor: '#EDF2F7', borderWidth: 1,
|
|
151
|
+
padding: [6, 10], textStyle: { color: INK(), fontSize: 12, fontFamily: FONT },
|
|
152
|
+
extraCssText: 'border-radius:6px;box-shadow:0 4px 16px rgba(107,131,160,0.15)',
|
|
153
|
+
},
|
|
154
|
+
categoryAxis: {
|
|
155
|
+
axisLine: { show: true, lineStyle: { color: INK(), width: 1 } },
|
|
156
|
+
axisTick: { show: false },
|
|
157
|
+
axisLabel: { color: INK(), fontFamily: FONT, fontSize: 12, hideOverlap: true },
|
|
158
|
+
splitLine: { show: false },
|
|
159
|
+
},
|
|
160
|
+
valueAxis: { show: false, splitLine: { show: false } },
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function merge(base, extra) {
|
|
164
|
+
if (Array.isArray(extra) || typeof extra !== 'object' || extra === null) return extra;
|
|
165
|
+
const out = { ...base };
|
|
166
|
+
for (const [key, value] of Object.entries(extra)) {
|
|
167
|
+
out[key] = typeof value === 'object' && value !== null && !Array.isArray(value) && typeof base?.[key] === 'object' ? merge(base[key], value) : value;
|
|
168
|
+
}
|
|
169
|
+
return out;
|
|
170
|
+
}
|
|
171
|
+
// form controls and buttons in Farseer's toolbar look: 28 px high, 12 px text, the focus ring drawn inside the
|
|
172
|
+
// control (so a control at the tile's edge never loses it), button text that never wraps, a long choice ending in …
|
|
173
|
+
// Farseer's own form controls and buttons (the app's input, select and button), the same in every tile
|
|
174
|
+
const CONTROL_CSS = `
|
|
175
|
+
.fs-control { font: 400 12px/20px ${FONT}; height: 32px; padding: 0 8px; border: 1px solid #EDF2F7; border-radius: 8px;
|
|
176
|
+
background-color: #EDF2F7; color: var(--code-tile-text); min-width: 0; max-width: 100%; box-sizing: border-box; outline: none;
|
|
177
|
+
overflow: hidden; white-space: nowrap; text-overflow: ellipsis; transition: border-color 100ms; }
|
|
178
|
+
select.fs-control { appearance: none; -webkit-appearance: none; padding-right: 32px; cursor: pointer;
|
|
179
|
+
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='%23020810' fill-rule='evenodd' d='M4.17 6.124a.5.5 0 01.706.047L8 9.74l3.124-3.57a.5.5 0 01.752.658l-3.5 4a.5.5 0 01-.752 0l-3.5-4a.5.5 0 01.047-.705z'/%3E%3C/svg%3E");
|
|
180
|
+
background-repeat: no-repeat; background-position: right 8px center; background-size: 16px 16px; }
|
|
181
|
+
.fs-control:hover { border-color: #C1CEDE; }
|
|
182
|
+
.fs-control:focus, .fs-control:focus-visible { border-color: #1966FF; outline: 1px solid #1966FF; outline-offset: 0; }
|
|
183
|
+
.fs-control.fs-empty, .fs-control::placeholder { color: var(--code-tile-muted); }
|
|
184
|
+
.fs-control:disabled { background-color: var(--code-tile-background); color: var(--code-tile-muted); cursor: not-allowed; }
|
|
185
|
+
.fs-button { font: 500 12px/14px ${FONT}; height: 32px; min-width: 32px; padding: 0 12px; white-space: nowrap; flex: none; border: none;
|
|
186
|
+
border-radius: 8px; cursor: pointer; background-color: #1966FF; color: #FFFFFF; transition: background-color 100ms, color 100ms; }
|
|
187
|
+
.fs-button:hover { background-color: #0942B2; }
|
|
188
|
+
.fs-button.fs-secondary { background-color: #E8F0FF; color: #1966FF; }
|
|
189
|
+
.fs-button.fs-secondary:hover { background-color: #C5D9FF; }
|
|
190
|
+
.fs-button.fs-tertiary { background-color: transparent; color: var(--code-tile-text); font-weight: 400; box-shadow: 0 0 0 1px var(--code-tile-border) inset; }
|
|
191
|
+
.fs-button.fs-tertiary:hover { background-color: #EDF2F7; }
|
|
192
|
+
.fs-button:disabled, .fs-button:disabled:hover { background-color: var(--code-tile-border); color: var(--code-tile-muted); box-shadow: none; cursor: not-allowed; }
|
|
193
|
+
.fs-button:focus-visible { outline: 1px solid var(--code-tile-text); outline-offset: 1px; }
|
|
194
|
+
.fs-button { display: inline-flex; align-items: center; justify-content: center; gap: 4px; }
|
|
195
|
+
.fs-chevron { width: 16px; height: 16px; flex: none; background-color: currentColor; -webkit-mask: center / 16px no-repeat; mask: center / 16px no-repeat; }
|
|
196
|
+
.fs-chevron-left { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M10.376 4.67a.5.5 0 01-.047.706L6.76 8.5l3.57 3.124a.5.5 0 11-.658.752l-4-3.5a.5.5 0 010-.752l4-3.5a.5.5 0 01.705.047z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M10.376 4.67a.5.5 0 01-.047.706L6.76 8.5l3.57 3.124a.5.5 0 11-.658.752l-4-3.5a.5.5 0 010-.752l4-3.5a.5.5 0 01.705.047z'/%3E%3C/svg%3E"); }
|
|
197
|
+
.fs-chevron-right { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M5.624 12.33a.5.5 0 01.047-.706L9.24 8.5 5.67 5.376a.5.5 0 11.658-.752l4 3.5a.5.5 0 010 .752l-4 3.5a.5.5 0 01-.705-.047z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M5.624 12.33a.5.5 0 01.047-.706L9.24 8.5 5.67 5.376a.5.5 0 11.658-.752l4 3.5a.5.5 0 010 .752l-4 3.5a.5.5 0 01-.705-.047z'/%3E%3C/svg%3E"); }
|
|
198
|
+
.fs-button.fs-icon-only { padding: 0; width: 32px; }`;
|
|
199
|
+
function control(tag, className = 'fs-control') {
|
|
200
|
+
if (!document.getElementById('fs-control-style')) {
|
|
201
|
+
const style = document.createElement('style');
|
|
202
|
+
style.id = 'fs-control-style';
|
|
203
|
+
style.textContent = CONTROL_CSS;
|
|
204
|
+
document.head.append(style);
|
|
205
|
+
}
|
|
206
|
+
const node = document.createElement(tag);
|
|
207
|
+
node.className = className;
|
|
208
|
+
return node;
|
|
209
|
+
}
|
|
210
|
+
// Farseer's table look (farseer-table.md): the same font, row height, header and rules as a table tile
|
|
211
|
+
const TABLE_CSS = `
|
|
212
|
+
.fs-table-wrap { width: fit-content; max-width: 100%; overflow: hidden; }
|
|
213
|
+
.fs-table { width: max-content; max-width: calc(100% + 12px); border-collapse: separate; border-spacing: 12px 0; margin: 0 0 0 -12px; font: 12px/1.2 ${FONT}; color: var(--code-tile-text); font-variant-numeric: tabular-nums; }
|
|
214
|
+
.fs-table th { height: 24px; padding: 0 0 5px; font-weight: 400; text-align: right; vertical-align: bottom; white-space: nowrap; background: linear-gradient(var(--code-tile-text), var(--code-tile-text)) bottom / 100% 1px no-repeat; }
|
|
215
|
+
.fs-table td { height: 24px; padding: 0; text-align: right; white-space: nowrap; background: linear-gradient(var(--code-tile-border), var(--code-tile-border)) bottom / 100% 1px no-repeat; }
|
|
216
|
+
.fs-table th:first-child, .fs-table td:first-child { text-align: left; }
|
|
217
|
+
.fs-table td:first-child { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
|
|
218
|
+
.fs-table tr.fs-total td { font-weight: 700; background-image: linear-gradient(var(--code-tile-text), var(--code-tile-text)); }
|
|
219
|
+
.fs-table tbody tr:hover td { background-color: color-mix(in srgb, var(--code-tile-muted) 8%, transparent); }
|
|
220
|
+
.fs-table .fs-good { color: ${GOOD}; } .fs-table .fs-bad { color: ${BAD}; } .fs-table .fs-muted { color: var(--code-tile-muted); }
|
|
221
|
+
.fs-table .fs-key { display: inline-block; width: 8px; height: 8px; margin-right: 8px; vertical-align: 0; }
|
|
222
|
+
.fs-table th.fs-AC, .fs-table tr:last-child td.fs-AC { background: linear-gradient(${AC}, ${AC}) bottom / 100% 3px no-repeat; }
|
|
223
|
+
.fs-table th.fs-PY, .fs-table tr:last-child td.fs-PY { background: linear-gradient(${AC_LIGHT}, ${AC_LIGHT}) bottom / 100% 3px no-repeat; }
|
|
224
|
+
.fs-table th.fs-PL, .fs-table tr:last-child td.fs-PL { background: linear-gradient(${AC}, ${AC}) bottom / 100% 1px no-repeat, linear-gradient(${AC}, ${AC}) 0 calc(100% - 3px) / 100% 1px no-repeat; }
|
|
225
|
+
.fs-table th.fs-FC, .fs-table tr:last-child td.fs-FC { background: repeating-linear-gradient(90deg, ${AC} 0 3px, transparent 3px 5px) bottom / 100% 3px no-repeat; }`;
|
|
226
|
+
function farseerTable(head, rows) {
|
|
227
|
+
// head: [{ label, key?, scenario?: 'AC' | 'PL' | 'PY' | 'FC' }] (a scenario column gets the table tile's rule
|
|
228
|
+
// under its header and its last row: AC thick, PL double, PY light, FC dotted);
|
|
229
|
+
// rows: [{ cells: [text or node, …], total?, tone?: [null | 'good' | 'bad' | 'muted', …] }]
|
|
230
|
+
if (!document.getElementById('fs-table-style')) {
|
|
231
|
+
const style = document.createElement('style');
|
|
232
|
+
style.id = 'fs-table-style';
|
|
233
|
+
style.textContent = TABLE_CSS;
|
|
234
|
+
document.head.append(style);
|
|
235
|
+
}
|
|
236
|
+
const table = el('table');
|
|
237
|
+
table.className = 'fs-table';
|
|
238
|
+
const tr = table.createTHead().insertRow();
|
|
239
|
+
for (const h of head) {
|
|
240
|
+
const th = el('th');
|
|
241
|
+
if (h.scenario) th.className = `fs-${h.scenario}`;
|
|
242
|
+
if (h.key) th.append(h.key);
|
|
243
|
+
th.append(h.label);
|
|
244
|
+
tr.append(th);
|
|
245
|
+
}
|
|
246
|
+
const body = table.createTBody();
|
|
247
|
+
for (const row of rows) {
|
|
248
|
+
const line = body.insertRow();
|
|
249
|
+
if (row.total) line.className = 'fs-total';
|
|
250
|
+
row.cells.forEach((cell, i) => {
|
|
251
|
+
const td = line.insertCell();
|
|
252
|
+
const classes = [row.tone?.[i] ? `fs-${row.tone[i]}` : '', head[i]?.scenario ? `fs-${head[i].scenario}` : ''].filter(Boolean);
|
|
253
|
+
if (classes.length) td.className = classes.join(' ');
|
|
254
|
+
if (cell instanceof Node) td.append(cell);
|
|
255
|
+
else td.textContent = cell ?? '';
|
|
256
|
+
if (i === 0 && typeof cell === 'string') td.title = cell;
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
// the first column gap reaches 12 px past the left edge, so the text lines up with the title; a clipping box keeps it inside the tile
|
|
260
|
+
const box = el('div');
|
|
261
|
+
box.className = 'fs-table-wrap';
|
|
262
|
+
box.append(table);
|
|
263
|
+
return box;
|
|
264
|
+
}
|
|
265
|
+
// a variance number in a table, as the table tile shows it: red when it hurts, ink when it helps
|
|
266
|
+
const tone = (delta, costLine) => (delta === null || delta === undefined ? 'muted' : (costLine ? delta > 0 : delta < 0) ? 'bad' : null);
|
|
267
|
+
// small HTML helpers for titles, notes and states, all in the theme's ink
|
|
268
|
+
function el(tag, css, text) {
|
|
269
|
+
const node = document.createElement(tag);
|
|
270
|
+
if (css) node.style.cssText = css;
|
|
271
|
+
if (text !== undefined) node.textContent = text;
|
|
272
|
+
return node;
|
|
273
|
+
}
|
|
274
|
+
// the tile header exactly as Farseer draws a chart or table tile's name: 12 px ink, regular, 10 px above the content;
|
|
275
|
+
// a note under it in the footnote style (11 px muted). The frame already sits inside the card's 8 px padding, so the
|
|
276
|
+
// tile's own content has no outer padding of its own
|
|
277
|
+
const TITLE = 'font-size:12px;font-weight:400;line-height:1.25;color:var(--code-tile-text)';
|
|
278
|
+
const NOTE = 'font-size:11px;line-height:1.35;color:var(--code-tile-muted)'; // footnotes and units only
|
|
279
|
+
const PAGE = 'display:grid;gap:10px;height:100%;padding:0;align-content:start';
|
|
280
|
+
const MESSAGE = 'display:grid;place-items:center;height:100%;font-size:13px;color:var(--code-tile-muted)';
|
|
281
|
+
// one title line, the way Farseer names tiles ("Net sales by region, year to date (kEUR)"); the scope only when the
|
|
282
|
+
// filter bar narrows it. A note the reader needs goes to the bottom in the footnote style, never under the title
|
|
283
|
+
// a value that rounds to zero carries no sign: "-0,0%" and "+0" become "0,0%" and "0"
|
|
284
|
+
const unsigned0 = (text) => String(text).replace(/^[+\-−](?=0(?:[.,]0+)?(?:\s?%|\s?pp)?$)/, '');
|
|
285
|
+
function heading(wrap, title) {
|
|
286
|
+
wrap.append(el('div', TITLE, title));
|
|
287
|
+
}
|
|
288
|
+
function footnote(wrap, text) {
|
|
289
|
+
wrap.append(el('div', `${NOTE};padding-top:2px`, text));
|
|
290
|
+
}
|
|
291
|
+
// the scope the filter bar sets, for titles: nothing for the whole group, the company, or "2 companies"
|
|
292
|
+
// (bar is the picks() the body opened for the tables a title names)
|
|
293
|
+
function scope(table, all, one) {
|
|
294
|
+
const pick = bar.current[table];
|
|
295
|
+
if (!pick || pick.all) return all;
|
|
296
|
+
if (pick.members.length === 1) return pick.members[0];
|
|
297
|
+
return `${pick.members.length} ${one}`;
|
|
298
|
+
}
|
|
299
|
+
function period() {
|
|
300
|
+
const ytd = bar.current['Year to date'];
|
|
301
|
+
const MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
|
|
302
|
+
if (!ytd || ytd.all || ytd.members.length !== 1) return 'year to date';
|
|
303
|
+
const m = Number(ytd.members[0].replace('M', ''));
|
|
304
|
+
return m === 1 ? 'January' : `January to ${MONTHS[m - 1]}`;
|
|
305
|
+
}
|
|
306
|
+
// --- end of the look ---
|
|
307
|
+
|
|
308
|
+
// the cells one row of the plan is made of: the cost centre, account and company picked in the tile, one month each
|
|
309
|
+
const FC = 'FC 8+4'; // the forecast version the model keeps open (its Reporting period member Current forecast)
|
|
310
|
+
const LAST_CLOSED = 8; // the model's last closed month (the Reporting setup page): earlier months are actuals
|
|
311
|
+
const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
312
|
+
// the department's cost centres: the list follows the Department picked in the filter bar (a cost centre links to
|
|
313
|
+
// its department); the ones with a budget are the ones to plan
|
|
314
|
+
const centres = readTable({
|
|
315
|
+
includeDashboardFilters: false,
|
|
316
|
+
rows: { table: 'Cost centre', includeDashboardFilters: true },
|
|
317
|
+
columns: [{ label: 'PL', formula: 'sum("OpEx", "Versions">"Budget 2026", "Reporting period">"Current year")' }],
|
|
318
|
+
});
|
|
319
|
+
const companies = ctx.query([{ type: 'DTABLE', table: 'Entity' }], { includeDashboardFilters: false, includeDashboardTimeline: false });
|
|
320
|
+
const pick = ctx.snapshot('pick', { centre: '', account: '6200 Advertising and digital marketing', entity: 'Acme Croatia' });
|
|
321
|
+
const edits = ctx.snapshot('edits', {});
|
|
322
|
+
// the last save: the months it wrote and its write handle (ctx.write redraws the tile when it starts and settles)
|
|
323
|
+
let saved = null;
|
|
324
|
+
let plan = null;
|
|
325
|
+
// the plan's 24 cells (PL and FC by month) for one pick, read live; a new pick closes the old read,
|
|
326
|
+
// since a tile holds at most ten open reads
|
|
327
|
+
function planFor(p) {
|
|
328
|
+
const cell = (version, m) => `sum("IMPORT_PnL", "Versions">"${version}", "Years">"Y2026", "Months">"M${m}", "Entity">"${p.entity}", "Cost centre">"${p.centre}", "P&L account">"${p.account}")`;
|
|
329
|
+
const key = JSON.stringify(p);
|
|
330
|
+
if (plan?.key !== key) {
|
|
331
|
+
plan?.read.close();
|
|
332
|
+
const formulas = MONTHS.flatMap((_, i) => [cell('Budget 2026', i + 1), cell(FC, i + 1)]);
|
|
333
|
+
plan = { key, cell, read: ctx.query(formulas.map((formula) => ({ type: 'VARIABLE', formula })), { includeDashboardFilters: false, includeDashboardTimeline: false }) };
|
|
334
|
+
}
|
|
335
|
+
return plan;
|
|
336
|
+
}
|
|
337
|
+
// a number the viewer typed, read in their own locale (en-US "13,000.5", de-DE "13.000,5"); null when the field is empty
|
|
338
|
+
function parseNumber(text) {
|
|
339
|
+
const parts = new Intl.NumberFormat(ctx.theme.numberLocale || 'en-US').formatToParts(12345.6);
|
|
340
|
+
const group = parts.find((p) => p.type === 'group')?.value ?? ',';
|
|
341
|
+
const decimal = parts.find((p) => p.type === 'decimal')?.value ?? '.';
|
|
342
|
+
const clean = String(text).trim().split(group).join('').replace(/\s/g, '').replace(decimal, '.');
|
|
343
|
+
return clean === '' ? null : Number(clean);
|
|
344
|
+
}
|
|
345
|
+
const number = parseNumber;
|
|
346
|
+
|
|
347
|
+
return (element) => {
|
|
348
|
+
const wrap = el('div', PAGE);
|
|
349
|
+
const chosen = bar.current.Department;
|
|
350
|
+
const department = chosen && !chosen.all && chosen.members.length === 1 ? chosen.members[0] : null;
|
|
351
|
+
heading(wrap, department ? `${department} forecast by month, ${FC} (EUR)` : `Forecast by month, ${FC} (EUR)`);
|
|
352
|
+
if (!department) {
|
|
353
|
+
wrap.append(el('div', MESSAGE, bar.loading ? '' : 'Pick one department in the filter bar to plan its months.'));
|
|
354
|
+
element.replaceChildren(wrap);
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
const plCol = centres.current.columns.findIndex((c) => c.label === 'PL');
|
|
358
|
+
const own = centres.current.rows.filter((r) => r.cells[plCol]?.value !== null).map((r) => r.label);
|
|
359
|
+
const p = { ...pick.value, centre: own.includes(pick.value.centre) ? pick.value.centre : own[0] ?? '' };
|
|
360
|
+
const select = (key, options) => {
|
|
361
|
+
const s = control('select');
|
|
362
|
+
s.id = `pick-${key}`;
|
|
363
|
+
for (const o of options) s.add(new Option(o, o, false, o === p[key]));
|
|
364
|
+
s.title = p[key];
|
|
365
|
+
s.onchange = () => {
|
|
366
|
+
pick.set({ ...p, [key]: s.value });
|
|
367
|
+
edits.set({});
|
|
368
|
+
saved = null;
|
|
369
|
+
ctx.render();
|
|
370
|
+
};
|
|
371
|
+
return s;
|
|
372
|
+
};
|
|
373
|
+
const fields = el('div');
|
|
374
|
+
fields.className = 'fs-picks';
|
|
375
|
+
fields.style.cssText = 'display:grid;grid-template-columns:repeat(auto-fit,minmax(160px,1fr));gap:8px 12px';
|
|
376
|
+
fields.append(select('centre', own), select('account', ['6200 Advertising and digital marketing', '6210 Trade marketing and promotions']), select('entity', namesOf(companies.current[0])));
|
|
377
|
+
wrap.append(fields);
|
|
378
|
+
if (!p.centre) {
|
|
379
|
+
wrap.append(el('div', MESSAGE, centres.loading ? '' : 'This department has no cost centre with a budget.'));
|
|
380
|
+
element.replaceChildren(wrap);
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
const current = planFor(p);
|
|
384
|
+
const values = current.read.current;
|
|
385
|
+
ctx.loading(current.read.loading);
|
|
386
|
+
const rows = MONTHS.map((name, i) => {
|
|
387
|
+
const m = i + 1;
|
|
388
|
+
const pl = values[2 * i]?.value ?? null;
|
|
389
|
+
const fc = values[2 * i + 1]?.value ?? null;
|
|
390
|
+
let fcCell;
|
|
391
|
+
if (m <= LAST_CLOSED) {
|
|
392
|
+
fcCell = ctx.format(fc, '#,##0'); // an actual: muted, the footnote says why
|
|
393
|
+
} else {
|
|
394
|
+
const input = control('input');
|
|
395
|
+
input.id = `fc-M${m}`;
|
|
396
|
+
input.inputMode = 'decimal';
|
|
397
|
+
input.style.cssText = 'width:96px;text-align:right';
|
|
398
|
+
input.value = edits.value[`M${m}`] ?? ctx.format(fc, '#,##0');
|
|
399
|
+
// typing must not redraw (that drops the focus): store the value and update the button only
|
|
400
|
+
input.oninput = () => {
|
|
401
|
+
edits.set({ ...edits.value, [`M${m}`]: input.value });
|
|
402
|
+
refresh();
|
|
403
|
+
};
|
|
404
|
+
fcCell = input;
|
|
405
|
+
}
|
|
406
|
+
return { cells: [`${name} 2026`, ctx.format(pl, '#,##0'), fcCell], tone: [null, null, m <= LAST_CLOSED ? 'muted' : null] };
|
|
407
|
+
});
|
|
408
|
+
wrap.append(farseerTable([{ label: 'Month' }, { label: 'PL', scenario: 'PL' }, { label: 'FC', scenario: 'FC' }], rows));
|
|
409
|
+
|
|
410
|
+
const changed = () => Object.entries(edits.value)
|
|
411
|
+
.map(([month, text]) => ({ m: Number(month.slice(1)), value: number(text) }))
|
|
412
|
+
.filter(({ m, value }) => value !== null && Number.isFinite(value) && value !== (values[2 * (m - 1) + 1]?.value ?? null));
|
|
413
|
+
const actions = el('div', 'display:flex;flex-wrap:wrap;justify-content:flex-end;align-items:center;gap:8px 12px');
|
|
414
|
+
const status = el('span', 'font-size:12px;color:var(--code-tile-muted)');
|
|
415
|
+
status.setAttribute('role', 'status');
|
|
416
|
+
const button = control('button', 'fs-button');
|
|
417
|
+
button.textContent = 'Save the forecast';
|
|
418
|
+
const said = (n) => {
|
|
419
|
+
if (n > 0) return `${n} ${n === 1 ? 'month' : 'months'} to save`;
|
|
420
|
+
if (saved?.handle.loading) return 'Saving…';
|
|
421
|
+
if (saved?.handle.error) return `Not saved: ${saved.handle.error.message}`;
|
|
422
|
+
if (saved) return `Saved ${saved.months.map((m) => MONTHS[m - 1]).join(', ')} into ${FC}.`;
|
|
423
|
+
return 'Change an open month to save it';
|
|
424
|
+
};
|
|
425
|
+
const refresh = () => {
|
|
426
|
+
const n = changed().length;
|
|
427
|
+
button.disabled = Boolean(saved?.handle.loading) || n === 0;
|
|
428
|
+
status.textContent = said(n);
|
|
429
|
+
};
|
|
430
|
+
refresh();
|
|
431
|
+
button.onclick = () => {
|
|
432
|
+
const list = changed();
|
|
433
|
+
if (list.length === 0) return;
|
|
434
|
+
// one write per open month, in one request: a month's cell, never the year (a year would spread)
|
|
435
|
+
saved = { months: list.map(({ m }) => m), handle: ctx.write(list.map(({ m, value }) => ({ type: 'VARIABLE', formula: current.cell(FC, m), value }))) };
|
|
436
|
+
edits.set({});
|
|
437
|
+
};
|
|
438
|
+
actions.append(status, button);
|
|
439
|
+
wrap.append(actions);
|
|
440
|
+
footnote(wrap, `PL is Budget 2026. Months to ${MONTHS[LAST_CLOSED - 1]} are closed, so FC shows their actuals in grey; the open months take what you type.`);
|
|
441
|
+
element.replaceChildren(wrap);
|
|
442
|
+
};
|
|
443
|
+
}
|