@odoo/o-spreadsheet 14.0.0 → 14.0.1
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/.eslintrc.json +20 -0
- package/.husky/post-checkout +9 -0
- package/.husky/pre-commit +39 -0
- package/.prettierignore +1 -0
- package/astToFormula.patch +0 -0
- package/demo/data.js +255 -0
- package/demo/index.html +9 -0
- package/demo/libs/Chart.bundle.js +20755 -0
- package/demo/main.js +101 -0
- package/doc/readme.md +46 -0
- package/package.json +3 -17
- package/rollup.config.js +23 -0
- package/src/base_plugin.ts +102 -0
- package/src/components/autofill.ts +146 -0
- package/src/components/bottom_bar.ts +199 -0
- package/src/components/color_picker.ts +150 -0
- package/src/components/composer/autocomplete_dropdown.ts +135 -0
- package/src/components/composer/composer.ts +487 -0
- package/src/components/composer/content_editable_helper.ts +146 -0
- package/src/components/figures/chart.ts +70 -0
- package/src/components/figures/container.ts +268 -0
- package/src/components/figures/text_figure.ts +36 -0
- package/src/components/grid.ts +635 -0
- package/src/components/helpers/dom_helpers.ts +7 -0
- package/src/components/helpers/drag_and_drop.ts +17 -0
- package/src/components/icons.ts +36 -0
- package/src/components/index.ts +1 -0
- package/src/components/menu.ts +288 -0
- package/src/components/overlay.ts +457 -0
- package/src/components/scrollbar.ts +22 -0
- package/src/components/selection_input.ts +168 -0
- package/src/components/side_panel/cell_is_rule_editor.ts +169 -0
- package/src/components/side_panel/chart_panel.ts +104 -0
- package/src/components/side_panel/color_scale_rule_editor.ts +145 -0
- package/src/components/side_panel/conditional_formatting.ts +396 -0
- package/src/components/side_panel/side_panel.ts +127 -0
- package/src/components/side_panel/translations_terms.ts +45 -0
- package/src/components/spreadsheet.ts +198 -0
- package/src/components/top_bar.ts +535 -0
- package/src/constants.ts +26 -0
- package/src/data.ts +149 -0
- package/src/fonts.ts +41 -0
- package/src/formulas/compiler.ts +258 -0
- package/src/formulas/composer_tokenizer.ts +70 -0
- package/src/formulas/index.ts +15 -0
- package/src/formulas/normalize.ts +52 -0
- package/src/formulas/parser.ts +280 -0
- package/src/formulas/range_tokenizer.ts +97 -0
- package/src/formulas/tokenizer.ts +242 -0
- package/src/functions/arguments.ts +114 -0
- package/src/functions/dates.ts +302 -0
- package/src/functions/helpers.ts +592 -0
- package/src/functions/index.ts +52 -0
- package/src/functions/module_database.ts +282 -0
- package/src/functions/module_date.ts +743 -0
- package/src/functions/module_info.ts +69 -0
- package/src/functions/module_logical.ts +208 -0
- package/src/functions/module_lookup.ts +185 -0
- package/src/functions/module_math.ts +1252 -0
- package/src/functions/module_operators.ts +291 -0
- package/src/functions/module_statistical.ts +882 -0
- package/src/functions/module_text.ts +370 -0
- package/src/helpers/color.ts +30 -0
- package/src/helpers/coordinates.ts +71 -0
- package/src/helpers/grid_manipulation.ts +68 -0
- package/src/helpers/index.ts +7 -0
- package/src/helpers/misc.ts +76 -0
- package/src/helpers/numbers.ts +117 -0
- package/src/helpers/uuid.ts +19 -0
- package/src/helpers/zones.ts +263 -0
- package/src/history.ts +186 -0
- package/src/index.ts +84 -0
- package/src/model.ts +261 -0
- package/src/plugins/autofill.ts +412 -0
- package/src/plugins/chart.ts +404 -0
- package/src/plugins/clipboard.ts +461 -0
- package/src/plugins/conditional_format.ts +445 -0
- package/src/plugins/core.ts +1502 -0
- package/src/plugins/edition.ts +157 -0
- package/src/plugins/evaluation.ts +428 -0
- package/src/plugins/figures.ts +123 -0
- package/src/plugins/formatting.ts +630 -0
- package/src/plugins/highlight.ts +187 -0
- package/src/plugins/index.ts +32 -0
- package/src/plugins/merge.ts +524 -0
- package/src/plugins/renderer.ts +571 -0
- package/src/plugins/selection.ts +562 -0
- package/src/plugins/selection_inputs.ts +326 -0
- package/src/registries/autofill_modifiers.ts +76 -0
- package/src/registries/autofill_rules.ts +98 -0
- package/src/registries/figure_registry.ts +30 -0
- package/src/registries/index.ts +7 -0
- package/src/registries/menu_items_registry.ts +110 -0
- package/src/registries/menus/cell_menu_registry.ts +79 -0
- package/src/registries/menus/col_menu_registry.ts +63 -0
- package/src/registries/menus/index.ts +6 -0
- package/src/registries/menus/menu_items_actions.ts +425 -0
- package/src/registries/menus/row_menu_registry.ts +63 -0
- package/src/registries/menus/sheet_menu_registry.ts +75 -0
- package/src/registries/menus/topbar_menu_registry.ts +204 -0
- package/src/registries/side_panel_registry.ts +26 -0
- package/src/registries/topbar_component_registry.ts +12 -0
- package/src/registry.ts +51 -0
- package/src/translation.ts +44 -0
- package/src/types/autofill.ts +48 -0
- package/src/types/chart.ts +26 -0
- package/src/types/commands.ts +716 -0
- package/src/types/conditional_formatting.ts +124 -0
- package/src/types/env.ts +13 -0
- package/src/types/functions.ts +35 -0
- package/src/types/getters.ts +103 -0
- package/src/types/index.ts +20 -0
- package/src/types/misc.ts +143 -0
- package/src/types/rendering.ts +41 -0
- package/src/types/workbook_data.ts +62 -0
- package/tests/__mocks__/uuid.ts +7 -0
- package/tests/canvas.mock.ts +34 -0
- package/tests/components/__mocks__/content_editable_helper.ts +79 -0
- package/tests/components/__mocks__/scrollbar.ts +18 -0
- package/tests/components/__snapshots__/autocomplete_dropdown_test.ts.snap +29 -0
- package/tests/components/__snapshots__/bottom_bar_test.ts.snap +75 -0
- package/tests/components/__snapshots__/context_menu_test.ts.snap +88 -0
- package/tests/components/__snapshots__/grid_test.ts.snap +60 -0
- package/tests/components/__snapshots__/spreadsheet_test.ts.snap +455 -0
- package/tests/components/__snapshots__/top_bar_test.ts.snap +705 -0
- package/tests/components/autocomplete_dropdown_test.ts +315 -0
- package/tests/components/autofill_test.ts +167 -0
- package/tests/components/bottom_bar_test.ts +262 -0
- package/tests/components/chart_side_panel_test.ts +123 -0
- package/tests/components/composer_test.ts +400 -0
- package/tests/components/context_menu_test.ts +825 -0
- package/tests/components/grid_manipulation_test.ts +163 -0
- package/tests/components/grid_test.ts +581 -0
- package/tests/components/overlay_test.ts +541 -0
- package/tests/components/selection_input_test.ts +259 -0
- package/tests/components/side_panel_test.ts +148 -0
- package/tests/components/spreadsheet_test.ts +194 -0
- package/tests/components/top_bar_test.ts +427 -0
- package/tests/data_test.ts +175 -0
- package/tests/dom_helper.ts +42 -0
- package/tests/formulas/__snapshots__/compiler_test.ts.snap +302 -0
- package/tests/formulas/compiler_test.ts +266 -0
- package/tests/formulas/composer_tokenizer_test.ts +137 -0
- package/tests/formulas/expressions_test.ts +57 -0
- package/tests/formulas/formulas_test.ts +80 -0
- package/tests/formulas/normalize_test.ts +82 -0
- package/tests/formulas/parser_test.ts +224 -0
- package/tests/formulas/range_tokenizer_test.ts +187 -0
- package/tests/formulas/tokenizer_test.ts +164 -0
- package/tests/functions/arguments_test.ts +141 -0
- package/tests/functions/dates_test.ts +1081 -0
- package/tests/functions/functions_test.ts +53 -0
- package/tests/functions/helper_test.ts +98 -0
- package/tests/functions/module_database_test.ts +311 -0
- package/tests/functions/module_date_test.ts +941 -0
- package/tests/functions/module_info_test.ts +139 -0
- package/tests/functions/module_logical_test.ts +369 -0
- package/tests/functions/module_lookup_test.ts +541 -0
- package/tests/functions/module_math_test.ts +2482 -0
- package/tests/functions/module_operators_test.ts +955 -0
- package/tests/functions/module_statistical_test.ts +2014 -0
- package/tests/functions/module_text_test.ts +667 -0
- package/tests/helpers/coordinates_test.ts +25 -0
- package/tests/helpers/misc_test.ts +95 -0
- package/tests/helpers/numbers_test.ts +196 -0
- package/tests/helpers/zones_test.ts +97 -0
- package/tests/helpers.ts +384 -0
- package/tests/menu_items_registry_test.ts +540 -0
- package/tests/model/plugins/__snapshots__/chart_test.ts.snap +90 -0
- package/tests/model/plugins/chart_test.ts +562 -0
- package/tests/model_test.ts +82 -0
- package/tests/plugins/__snapshots__/conditional_formatting_test.ts.snap +131 -0
- package/tests/plugins/__snapshots__/renderer_test.ts.snap +371 -0
- package/tests/plugins/autofill_test.ts +457 -0
- package/tests/plugins/borders_test.ts +295 -0
- package/tests/plugins/clipboard_test.ts +1180 -0
- package/tests/plugins/conditional_formatting_test.ts +1253 -0
- package/tests/plugins/core_test.ts +614 -0
- package/tests/plugins/edition_test.ts +100 -0
- package/tests/plugins/evaluation_async_test.ts +332 -0
- package/tests/plugins/evaluation_dates_test.ts +79 -0
- package/tests/plugins/evaluation_test.ts +901 -0
- package/tests/plugins/figures_test.ts +327 -0
- package/tests/plugins/formatting_test.ts +391 -0
- package/tests/plugins/grid_manipulation_test.ts +1366 -0
- package/tests/plugins/highlight_test.ts +413 -0
- package/tests/plugins/history_test.ts +142 -0
- package/tests/plugins/import_export_test.ts +276 -0
- package/tests/plugins/merges_test.ts +490 -0
- package/tests/plugins/navigation_test.ts +181 -0
- package/tests/plugins/plugins/evaluation_test.ts +111 -0
- package/tests/plugins/renderer_test.ts +598 -0
- package/tests/plugins/resizing_test.ts +152 -0
- package/tests/plugins/selection_input_test.ts +409 -0
- package/tests/plugins/selection_test.ts +442 -0
- package/tests/plugins/sheets_test.ts +643 -0
- package/tests/plugins/style_test.ts +90 -0
- package/tsconfig.json +22 -0
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
import * as owl from "@odoo/owl";
|
|
2
|
+
import { colorNumberString, uuidv4 } from "../../helpers/index";
|
|
3
|
+
import {
|
|
4
|
+
ColorScaleRule,
|
|
5
|
+
ConditionalFormat,
|
|
6
|
+
SingleColorRules,
|
|
7
|
+
SpreadsheetEnv,
|
|
8
|
+
UID,
|
|
9
|
+
Zone,
|
|
10
|
+
} from "../../types";
|
|
11
|
+
import { SelectionInput } from "../selection_input";
|
|
12
|
+
import { CellIsRuleEditor } from "./cell_is_rule_editor";
|
|
13
|
+
import { ColorScaleRuleEditor } from "./color_scale_rule_editor";
|
|
14
|
+
import { cellIsOperators } from "./translations_terms";
|
|
15
|
+
|
|
16
|
+
const { Component, useState } = owl;
|
|
17
|
+
const { xml, css } = owl.tags;
|
|
18
|
+
|
|
19
|
+
// TODO vsc: add ordering of rules
|
|
20
|
+
const PREVIEW_TEMPLATE = xml/* xml */ `
|
|
21
|
+
<div class="o-cf-preview">
|
|
22
|
+
<div t-att-style="getStyle(cf.rule)" class="o-cf-preview-image">
|
|
23
|
+
123
|
|
24
|
+
</div>
|
|
25
|
+
<div class="o-cf-preview-description">
|
|
26
|
+
<div class="o-cf-preview-ruletype">
|
|
27
|
+
<div class="o-cf-preview-description-rule">
|
|
28
|
+
<t t-esc="getDescription(cf)" />
|
|
29
|
+
</div>
|
|
30
|
+
<div class="o-cf-preview-description-values">
|
|
31
|
+
<t t-if="cf.rule.values">
|
|
32
|
+
<t t-esc="cf.rule.values[0]" />
|
|
33
|
+
<t t-if="cf.rule.values[1]">
|
|
34
|
+
and <t t-esc="cf.rule.values[1]"/>
|
|
35
|
+
</t>
|
|
36
|
+
</t>
|
|
37
|
+
</div>
|
|
38
|
+
</div>
|
|
39
|
+
<div class="o-cf-preview-range" t-esc="cf.ranges"/>
|
|
40
|
+
</div>
|
|
41
|
+
<div class="o-cf-delete">
|
|
42
|
+
<div class="o-cf-delete-button" t-on-click.stop="onDeleteClick(cf)" aria-label="Remove rule">
|
|
43
|
+
x
|
|
44
|
+
</div>
|
|
45
|
+
</div>
|
|
46
|
+
</div>`;
|
|
47
|
+
|
|
48
|
+
const TEMPLATE = xml/* xml */ `
|
|
49
|
+
<div class="o-cf">
|
|
50
|
+
<t t-if="state.mode === 'list'">
|
|
51
|
+
<div class="o-cf-preview-list" >
|
|
52
|
+
<div t-on-click="onRuleClick(cf)" t-foreach="getters.getConditionalFormats()" t-as="cf" t-key="cf.id">
|
|
53
|
+
<t t-call="${PREVIEW_TEMPLATE}"/>
|
|
54
|
+
</div>
|
|
55
|
+
</div>
|
|
56
|
+
</t>
|
|
57
|
+
<t t-if="state.mode === 'edit' || state.mode === 'add'" t-key="state.currentCF.id">
|
|
58
|
+
<div class="o-cf-type-selector">
|
|
59
|
+
<div class="o-cf-type-tab" t-att-class="{'o-cf-tab-selected': state.toRuleType === 'CellIsRule'}" t-on-click="setRuleType('CellIsRule')">Single Color</div>
|
|
60
|
+
<div class="o-cf-type-tab" t-att-class="{'o-cf-tab-selected': state.toRuleType === 'ColorScaleRule'}" t-on-click="setRuleType('ColorScaleRule')">Color Scale</div>
|
|
61
|
+
</div>
|
|
62
|
+
<div class="o-cf-ruleEditor">
|
|
63
|
+
<div class="o-section o-cf-range">
|
|
64
|
+
<div class="o-section-title">Apply to range</div>
|
|
65
|
+
<SelectionInput ranges="state.currentRanges" class="o-range" t-on-selection-changed="onRangesChanged"/>
|
|
66
|
+
</div>
|
|
67
|
+
<div class="o-cf-editor o-section">
|
|
68
|
+
<t t-component="editors[state.currentCF.rule.type]"
|
|
69
|
+
t-key="state.currentCF.id"
|
|
70
|
+
conditionalFormat="state.currentCF"
|
|
71
|
+
t-on-cancel-edit="onCancel"
|
|
72
|
+
t-on-modify-rule="onSave" />
|
|
73
|
+
</div>
|
|
74
|
+
</div>
|
|
75
|
+
</t>
|
|
76
|
+
<div class="o-cf-add" t-if="state.mode === 'list'" t-on-click.prevent.stop="onAdd">
|
|
77
|
+
+ Add another rule
|
|
78
|
+
</div>
|
|
79
|
+
</div>`;
|
|
80
|
+
|
|
81
|
+
const CSS = css/* scss */ `
|
|
82
|
+
.o-cf {
|
|
83
|
+
min-width: 350px;
|
|
84
|
+
.o-cf-type-selector {
|
|
85
|
+
margin-top: 20px;
|
|
86
|
+
display: flex;
|
|
87
|
+
.o-cf-type-tab {
|
|
88
|
+
cursor: pointer;
|
|
89
|
+
flex-grow: 1;
|
|
90
|
+
text-align: center;
|
|
91
|
+
}
|
|
92
|
+
.o-cf-tab-selected {
|
|
93
|
+
text-decoration: underline;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
.o-cf-preview {
|
|
97
|
+
background-color: #fff;
|
|
98
|
+
border-bottom: 1px solid #ccc;
|
|
99
|
+
cursor: pointer;
|
|
100
|
+
display: flex;
|
|
101
|
+
height: 60px;
|
|
102
|
+
padding: 10px;
|
|
103
|
+
position: relative;
|
|
104
|
+
&:hover {
|
|
105
|
+
background-color: rgba(0, 0, 0, 0.08);
|
|
106
|
+
}
|
|
107
|
+
&:not(:hover) .o-cf-delete-button {
|
|
108
|
+
display: none;
|
|
109
|
+
}
|
|
110
|
+
.o-cf-preview-image {
|
|
111
|
+
border: 1px solid lightgrey;
|
|
112
|
+
height: 50px;
|
|
113
|
+
line-height: 50px;
|
|
114
|
+
margin-right: 15px;
|
|
115
|
+
position: absolute;
|
|
116
|
+
text-align: center;
|
|
117
|
+
width: 50px;
|
|
118
|
+
}
|
|
119
|
+
.o-cf-preview-description {
|
|
120
|
+
left: 65px;
|
|
121
|
+
margin-bottom: auto;
|
|
122
|
+
margin-right: 8px;
|
|
123
|
+
margin-top: auto;
|
|
124
|
+
position: relative;
|
|
125
|
+
width: 142px;
|
|
126
|
+
.o-cf-preview-description-rule {
|
|
127
|
+
margin-bottom: 4px;
|
|
128
|
+
overflow: hidden;
|
|
129
|
+
}
|
|
130
|
+
.o-cf-preview-description-values {
|
|
131
|
+
overflow: hidden;
|
|
132
|
+
}
|
|
133
|
+
.o-cf-preview-range {
|
|
134
|
+
text-overflow: ellipsis;
|
|
135
|
+
font-size: 12px;
|
|
136
|
+
overflow: hidden;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
.o-cf-delete {
|
|
140
|
+
height: 56px;
|
|
141
|
+
left: 90%;
|
|
142
|
+
line-height: 56px;
|
|
143
|
+
position: absolute;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
.o-cf-ruleEditor {
|
|
147
|
+
.o-dropdown {
|
|
148
|
+
position: relative;
|
|
149
|
+
.o-dropdown-content {
|
|
150
|
+
position: absolute;
|
|
151
|
+
top: calc(100% + 5px);
|
|
152
|
+
left: 0;
|
|
153
|
+
z-index: 10;
|
|
154
|
+
box-shadow: 1px 2px 5px 2px rgba(51, 51, 51, 0.15);
|
|
155
|
+
background-color: #f6f6f6;
|
|
156
|
+
|
|
157
|
+
.o-dropdown-item {
|
|
158
|
+
padding: 7px 10px;
|
|
159
|
+
}
|
|
160
|
+
.o-dropdown-item:hover {
|
|
161
|
+
background-color: rgba(0, 0, 0, 0.08);
|
|
162
|
+
}
|
|
163
|
+
.o-dropdown-line {
|
|
164
|
+
display: flex;
|
|
165
|
+
padding: 3px 6px;
|
|
166
|
+
.o-line-item {
|
|
167
|
+
width: 16px;
|
|
168
|
+
height: 16px;
|
|
169
|
+
margin: 1px 3px;
|
|
170
|
+
&:hover {
|
|
171
|
+
background-color: rgba(0, 0, 0, 0.08);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
.o-tools {
|
|
179
|
+
color: #333;
|
|
180
|
+
font-size: 13px;
|
|
181
|
+
cursor: default;
|
|
182
|
+
display: flex;
|
|
183
|
+
|
|
184
|
+
.o-tool {
|
|
185
|
+
display: flex;
|
|
186
|
+
align-items: center;
|
|
187
|
+
margin: 2px;
|
|
188
|
+
padding: 0 3px;
|
|
189
|
+
border-radius: 2px;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
.o-tool.active,
|
|
193
|
+
.o-tool:not(.o-disabled):hover {
|
|
194
|
+
background-color: rgba(0, 0, 0, 0.08);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
.o-with-color > span {
|
|
198
|
+
border-bottom: 4px solid;
|
|
199
|
+
height: 16px;
|
|
200
|
+
margin-top: 2px;
|
|
201
|
+
}
|
|
202
|
+
.o-with-color {
|
|
203
|
+
.o-line-item:hover {
|
|
204
|
+
outline: 1px solid gray;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
.o-border {
|
|
208
|
+
.o-line-item {
|
|
209
|
+
padding: 4px;
|
|
210
|
+
margin: 1px;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
.o-cell-content {
|
|
215
|
+
font-size: 12px;
|
|
216
|
+
font-weight: 500;
|
|
217
|
+
padding: 0 12px;
|
|
218
|
+
margin: 0;
|
|
219
|
+
line-height: 35px;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
.o-cf-add {
|
|
223
|
+
font-size: 14px;
|
|
224
|
+
height: 36px;
|
|
225
|
+
padding: 20px 24px 11px 24px;
|
|
226
|
+
height: 44px;
|
|
227
|
+
cursor: pointer;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
`;
|
|
231
|
+
interface Props {
|
|
232
|
+
selection?: [Zone];
|
|
233
|
+
}
|
|
234
|
+
export class ConditionalFormattingPanel extends Component<Props, SpreadsheetEnv> {
|
|
235
|
+
static template = TEMPLATE;
|
|
236
|
+
static style = CSS;
|
|
237
|
+
static components = { CellIsRuleEditor, ColorScaleRuleEditor, SelectionInput };
|
|
238
|
+
colorNumberString = colorNumberString;
|
|
239
|
+
getters = this.env.getters;
|
|
240
|
+
private activeSheetId: UID;
|
|
241
|
+
|
|
242
|
+
//@ts-ignore --> used in XML template
|
|
243
|
+
private cellIsOperators = cellIsOperators;
|
|
244
|
+
state = useState({
|
|
245
|
+
currentCF: undefined as undefined | ConditionalFormat,
|
|
246
|
+
currentRanges: [] as string[],
|
|
247
|
+
mode: "list" as "list" | "edit" | "add",
|
|
248
|
+
toRuleType: "CellIsRule",
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
editors = {
|
|
252
|
+
CellIsRule: CellIsRuleEditor,
|
|
253
|
+
ColorScaleRule: ColorScaleRuleEditor,
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
constructor(parent, props: Props) {
|
|
257
|
+
super(parent, props);
|
|
258
|
+
this.activeSheetId = this.getters.getActiveSheet();
|
|
259
|
+
if (props.selection && this.getters.getRulesSelection(props.selection).length === 1) {
|
|
260
|
+
this.openCf(this.getters.getRulesSelection(props.selection)[0]);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
async willUpdateProps(nextProps: Props) {
|
|
264
|
+
const newActiveSheetId = this.getters.getActiveSheet();
|
|
265
|
+
if (newActiveSheetId !== this.activeSheetId) {
|
|
266
|
+
this.activeSheetId = newActiveSheetId;
|
|
267
|
+
this.resetState();
|
|
268
|
+
} else if (nextProps.selection && nextProps.selection !== this.props.selection)
|
|
269
|
+
if (nextProps.selection && this.getters.getRulesSelection(nextProps.selection).length === 1) {
|
|
270
|
+
this.openCf(this.getters.getRulesSelection(nextProps.selection)[0]);
|
|
271
|
+
} else {
|
|
272
|
+
this.resetState();
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
resetState() {
|
|
277
|
+
this.state.currentCF = undefined;
|
|
278
|
+
this.state.currentRanges = [];
|
|
279
|
+
this.state.mode = "list";
|
|
280
|
+
this.state.toRuleType = "CellIsRule";
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
getStyle(rule: SingleColorRules | ColorScaleRule): string {
|
|
284
|
+
if (rule.type === "CellIsRule") {
|
|
285
|
+
const cellRule = rule as SingleColorRules;
|
|
286
|
+
const fontWeight = cellRule.style.bold ? "bold" : "normal";
|
|
287
|
+
const fontDecoration = cellRule.style.strikethrough ? "line-through" : "none";
|
|
288
|
+
const fontStyle = cellRule.style.italic ? "italic" : "normal";
|
|
289
|
+
const color = cellRule.style.textColor || "none";
|
|
290
|
+
const backgroundColor = cellRule.style.fillColor || "none";
|
|
291
|
+
return `font-weight:${fontWeight};
|
|
292
|
+
text-decoration:${fontDecoration};
|
|
293
|
+
font-style:${fontStyle};
|
|
294
|
+
color:${color};
|
|
295
|
+
background-color:${backgroundColor};`;
|
|
296
|
+
} else {
|
|
297
|
+
const colorScale = rule as ColorScaleRule;
|
|
298
|
+
return `background-image: linear-gradient(to right, #${colorNumberString(
|
|
299
|
+
colorScale.minimum.color
|
|
300
|
+
)}, #${colorNumberString(colorScale.maximum.color)})`;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
getDescription(cf: ConditionalFormat): string {
|
|
305
|
+
return cf.rule.type === "CellIsRule" ? cellIsOperators[cf.rule.operator] : "Color scale";
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
onSave(ev: CustomEvent) {
|
|
309
|
+
if (this.state.currentCF) {
|
|
310
|
+
this.env.dispatch("ADD_CONDITIONAL_FORMAT", {
|
|
311
|
+
cf: {
|
|
312
|
+
rule: ev.detail.rule,
|
|
313
|
+
ranges: this.state.currentRanges,
|
|
314
|
+
id: this.state.mode === "edit" ? this.state.currentCF.id : uuidv4(),
|
|
315
|
+
},
|
|
316
|
+
sheet: this.getters.getActiveSheet(),
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
this.state.mode = "list";
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
onCancel() {
|
|
323
|
+
this.state.mode = "list";
|
|
324
|
+
this.state.currentCF = undefined;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
onDeleteClick(cf: ConditionalFormat) {
|
|
328
|
+
this.env.dispatch("REMOVE_CONDITIONAL_FORMAT", {
|
|
329
|
+
id: cf.id,
|
|
330
|
+
sheet: this.getters.getActiveSheet(),
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
onRuleClick(cf) {
|
|
334
|
+
this.state.mode = "edit";
|
|
335
|
+
this.state.currentCF = cf;
|
|
336
|
+
this.state.toRuleType = cf.rule.type === "CellIsRule" ? "CellIsRule" : "ColorScaleRule";
|
|
337
|
+
this.state.currentRanges = this.state.currentCF!.ranges;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
openCf(cfId) {
|
|
341
|
+
const rules = this.getters.getConditionalFormats();
|
|
342
|
+
const cfIndex = rules.findIndex((c) => c.id === cfId);
|
|
343
|
+
const cf = rules[cfIndex];
|
|
344
|
+
if (cf) {
|
|
345
|
+
this.state.mode = "edit";
|
|
346
|
+
this.state.currentCF = cf;
|
|
347
|
+
this.state.toRuleType = cf.rule.type === "CellIsRule" ? "CellIsRule" : "ColorScaleRule";
|
|
348
|
+
this.state.currentRanges = this.state.currentCF!.ranges;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
defaultCellIsRule(): ConditionalFormat {
|
|
353
|
+
return {
|
|
354
|
+
rule: {
|
|
355
|
+
type: "CellIsRule",
|
|
356
|
+
operator: "Equal",
|
|
357
|
+
values: [],
|
|
358
|
+
style: { fillColor: "#FF0000" },
|
|
359
|
+
},
|
|
360
|
+
ranges: this.getters.getSelectedZones().map(this.getters.zoneToXC),
|
|
361
|
+
id: uuidv4(),
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
defaultColorScaleRule(): ConditionalFormat {
|
|
366
|
+
return {
|
|
367
|
+
rule: {
|
|
368
|
+
minimum: { type: "value", color: 0 },
|
|
369
|
+
maximum: { type: "value", color: 0xeeffee },
|
|
370
|
+
type: "ColorScaleRule",
|
|
371
|
+
},
|
|
372
|
+
ranges: this.getters.getSelectedZones().map(this.getters.zoneToXC),
|
|
373
|
+
id: uuidv4(),
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
onAdd() {
|
|
378
|
+
this.state.mode = "add";
|
|
379
|
+
this.state.currentCF = this.defaultCellIsRule();
|
|
380
|
+
this.state.currentRanges = this.state.currentCF!.ranges;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
setRuleType(ruleType: string) {
|
|
384
|
+
if (ruleType === "ColorScaleRule") {
|
|
385
|
+
this.state.currentCF = this.defaultColorScaleRule();
|
|
386
|
+
}
|
|
387
|
+
if (ruleType === "CellIsRule") {
|
|
388
|
+
this.state.currentCF = this.defaultCellIsRule();
|
|
389
|
+
}
|
|
390
|
+
this.state.toRuleType = ruleType;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
onRangesChanged({ detail }: { detail: { ranges: string[] } }) {
|
|
394
|
+
this.state.currentRanges = detail.ranges;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import * as owl from "@odoo/owl";
|
|
2
|
+
import { SidePanelContent, sidePanelRegistry } from "../../registries/side_panel_registry";
|
|
3
|
+
import { SpreadsheetEnv } from "../../types";
|
|
4
|
+
|
|
5
|
+
const { Component } = owl;
|
|
6
|
+
const { xml, css } = owl.tags;
|
|
7
|
+
const { useState } = owl.hooks;
|
|
8
|
+
|
|
9
|
+
const TEMPLATE = xml/* xml */ `
|
|
10
|
+
<div class="o-sidePanel" >
|
|
11
|
+
<div class="o-sidePanelHeader">
|
|
12
|
+
<div class="o-sidePanelTitle" t-esc="getTitle()"/>
|
|
13
|
+
<div class="o-sidePanelClose" t-on-click="trigger('close-side-panel')">×</div>
|
|
14
|
+
</div>
|
|
15
|
+
<div class="o-sidePanelBody">
|
|
16
|
+
<t t-component="state.panel.Body" t-props="props.panelProps" t-key="'Body_' + props.component"/>
|
|
17
|
+
</div>
|
|
18
|
+
<div class="o-sidePanelFooter" t-if="state.panel.Footer">
|
|
19
|
+
<t t-component="state.panel.Footer" t-props="props.panelProps" t-key="'Footer_' + props.component"/>
|
|
20
|
+
</div>
|
|
21
|
+
</div>`;
|
|
22
|
+
|
|
23
|
+
const CSS = css/* scss */ `
|
|
24
|
+
.o-sidePanel {
|
|
25
|
+
display: flex;
|
|
26
|
+
flex-direction: column;
|
|
27
|
+
overflow-x: hidden;
|
|
28
|
+
background-color: white;
|
|
29
|
+
border: 1px solid darkgray;
|
|
30
|
+
.o-sidePanelHeader {
|
|
31
|
+
padding: 6px;
|
|
32
|
+
height: 30px;
|
|
33
|
+
background-color: #f8f9fa;
|
|
34
|
+
display: flex;
|
|
35
|
+
align-items: center;
|
|
36
|
+
justify-content: space-between;
|
|
37
|
+
border-bottom: 1px solid darkgray;
|
|
38
|
+
font-weight: bold;
|
|
39
|
+
.o-sidePanelTitle {
|
|
40
|
+
font-weight: bold;
|
|
41
|
+
padding: 5px 10px;
|
|
42
|
+
font-size: 1.2rem;
|
|
43
|
+
}
|
|
44
|
+
.o-sidePanelClose {
|
|
45
|
+
font-size: 1.5rem;
|
|
46
|
+
padding: 5px 10px;
|
|
47
|
+
cursor: pointer;
|
|
48
|
+
&:hover {
|
|
49
|
+
background-color: WhiteSmoke;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
.o-sidePanelBody {
|
|
54
|
+
overflow: auto;
|
|
55
|
+
width: 100%;
|
|
56
|
+
height: 100%;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.o-sidePanelButtons {
|
|
60
|
+
padding: 5px 16px;
|
|
61
|
+
text-align: right;
|
|
62
|
+
.o-sidePanelButton {
|
|
63
|
+
border: 1px solid lightgrey;
|
|
64
|
+
padding: 0px 20px 0px 20px;
|
|
65
|
+
border-radius: 4px;
|
|
66
|
+
font-weight: 500;
|
|
67
|
+
font-size: 14px;
|
|
68
|
+
height: 30px;
|
|
69
|
+
line-height: 16px;
|
|
70
|
+
background: white;
|
|
71
|
+
cursor: pointer;
|
|
72
|
+
margin-right: 8px;
|
|
73
|
+
&:hover {
|
|
74
|
+
background-color: rgba(0, 0, 0, 0.08);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
.o-sidePanelButton:last-child {
|
|
78
|
+
margin-right: 0px;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
.o-input {
|
|
82
|
+
border-radius: 4px;
|
|
83
|
+
border: 1px solid lightgrey;
|
|
84
|
+
padding: 4px 6px;
|
|
85
|
+
width: 96%;
|
|
86
|
+
.o-type-selector {
|
|
87
|
+
background-position: right 5px top 11px;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
select.o-input {
|
|
91
|
+
background-color: white;
|
|
92
|
+
text-align: left;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.o-section {
|
|
96
|
+
padding: 16px;
|
|
97
|
+
.o-section-title {
|
|
98
|
+
font-weight: bold;
|
|
99
|
+
margin-bottom: 5px;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
`;
|
|
104
|
+
|
|
105
|
+
interface Props {
|
|
106
|
+
component: string;
|
|
107
|
+
panelProps: any;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export class SidePanel extends Component<Props, SpreadsheetEnv> {
|
|
111
|
+
static template = TEMPLATE;
|
|
112
|
+
static style = CSS;
|
|
113
|
+
|
|
114
|
+
state: { panel: SidePanelContent } = useState({
|
|
115
|
+
panel: sidePanelRegistry.get(this.props.component),
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
async willUpdateProps(nextProps: Props) {
|
|
119
|
+
this.state.panel = sidePanelRegistry.get(nextProps.component);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
getTitle() {
|
|
123
|
+
return typeof this.state.panel.title === "function"
|
|
124
|
+
? this.state.panel.title(this.env)
|
|
125
|
+
: this.state.panel.title;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { _lt } from "../../translation";
|
|
2
|
+
|
|
3
|
+
export const terms = {
|
|
4
|
+
CF_TITLE: _lt("Format rules"),
|
|
5
|
+
IS_RULE: _lt("Format cells if..."),
|
|
6
|
+
FORMATTING_STYLE: _lt("Formatting style"),
|
|
7
|
+
BOLD: _lt("Bold"),
|
|
8
|
+
ITALIC: _lt("Italic"),
|
|
9
|
+
STRIKETHROUGH: _lt("Strikethrough"),
|
|
10
|
+
TEXTCOLOR: _lt("Text Color"),
|
|
11
|
+
FILLCOLOR: _lt("Fill Color"),
|
|
12
|
+
CANCEL: _lt("Cancel"),
|
|
13
|
+
SAVE: _lt("Save"),
|
|
14
|
+
PREVIEWTEXT: _lt("Preview text"),
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const cellIsOperators = {
|
|
18
|
+
BeginsWith: _lt("Begins with"),
|
|
19
|
+
Between: _lt("Between"),
|
|
20
|
+
ContainsText: _lt("Contains text"),
|
|
21
|
+
EndsWith: _lt("Ends with"),
|
|
22
|
+
Equal: _lt("Is equal to"),
|
|
23
|
+
GreaterThan: _lt("Greater than"),
|
|
24
|
+
GreaterThanOrEqual: _lt("Greater than or equal"),
|
|
25
|
+
LessThan: _lt("Less than"),
|
|
26
|
+
LessThanOrEqual: _lt("Less than or equal"),
|
|
27
|
+
NotBetween: _lt("Not between"),
|
|
28
|
+
NotContains: _lt("Not contains"),
|
|
29
|
+
NotEqual: _lt("Not equal"),
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const chartTerms = {
|
|
33
|
+
ChartType: _lt("Chart type"),
|
|
34
|
+
Line: _lt("Line"),
|
|
35
|
+
Bar: _lt("Bar"),
|
|
36
|
+
Pie: _lt("Pie"),
|
|
37
|
+
Title: _lt("Title"),
|
|
38
|
+
Series: _lt("Series"),
|
|
39
|
+
DataSeries: _lt("Data Series"),
|
|
40
|
+
MyDataHasTitle: _lt("My data has title"),
|
|
41
|
+
DataCategories: _lt("Data categories (labels)"),
|
|
42
|
+
UpdateChart: _lt("Update chart"),
|
|
43
|
+
CreateChart: _lt("Create chart"),
|
|
44
|
+
TitlePlaceholder: _lt("New Chart"),
|
|
45
|
+
};
|