not-bulma 1.0.91 → 1.0.93

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "not-bulma",
3
- "version": "1.0.91",
3
+ "version": "1.0.93",
4
4
  "description": "not-* family UI components on Bulma CSS Framework",
5
5
  "main": "src/index.js",
6
6
  "svelte": "src/index.js",
@@ -1,4 +1,5 @@
1
1
  <script>
2
+ import UICommon from "../common";
2
3
  import ErrorsList from "../various/ui.errors.list.svelte";
3
4
  import { createEventDispatcher } from "svelte";
4
5
  let dispatch = createEventDispatcher();
@@ -24,6 +24,8 @@
24
24
  export let formErrors = false;
25
25
  export let formLevelError = false;
26
26
 
27
+ let selectedVariants = [];
28
+
27
29
  $: iconClasses = (icon ? " has-icons-left " : "") + " has-icons-right ";
28
30
  $: allErrors = [].concat(
29
31
  errors ? errors : [],
@@ -36,9 +38,12 @@
36
38
  ? UICommon.CLASS_OK
37
39
  : UICommon.CLASS_ERR;
38
40
  $: multipleClass = multiple ? " is-multiple " : "";
39
- $: selectedVariants = Array.isArray(variants)
40
- ? variants.filter(filterSelectedVariants)
41
- : [];
41
+ $: {
42
+ value;
43
+ selectedVariants = Array.isArray(variants)
44
+ ? variants.filter(filterSelectedVariants)
45
+ : [];
46
+ }
42
47
 
43
48
  function filterSelectedVariants(variant) {
44
49
  if (Array.isArray(value) && multiple) {
@@ -155,6 +155,14 @@ class notTable extends EventEmitter {
155
155
  }
156
156
  }
157
157
 
158
+ onFilterChange(filter) {
159
+ if (filter) {
160
+ this.setFilter(filter);
161
+ } else {
162
+ this.resetFilter();
163
+ }
164
+ }
165
+
158
166
  onSelectedUpdate(val) {
159
167
  this.data.selected = val;
160
168
  }
@@ -211,6 +219,7 @@ class notTable extends EventEmitter {
211
219
  this.ui.table = new this.options.ui({
212
220
  target: this.options.targetEl,
213
221
  props: {
222
+ filterUI: this.getOptions("filterUI", undefined),
214
223
  id: this.id,
215
224
  helpers: Object.assign({}, this.getHelpers()),
216
225
  fields: this.getOptions("fields"),
@@ -221,10 +230,12 @@ class notTable extends EventEmitter {
221
230
  showSearch: this.getOptions("showSearch"),
222
231
  idField: this.getOptions("idField"),
223
232
  getItemId: this.getOptions("getItemId"),
233
+ filter: this.getFilter(),
224
234
  },
225
235
  });
226
236
  }
227
237
  this.ui.table.$on("searchChange", (e) => this.onSearchChange(e.detail));
238
+ this.ui.table.$on("filterChange", (e) => this.onFilterChange(e.detail));
228
239
  this.ui.table.$on("goToPage", (e) => this.goToPage(e.detail));
229
240
  this.ui.table.$on("goToNextPage", () => this.goToNext());
230
241
  this.ui.table.$on("goToPrevPage", () => this.goToPrev());
@@ -1,140 +1,198 @@
1
1
  <script>
2
- import {LOCALE} from '../../../locale';
3
-
4
- import * as Stores from './stores.js';
5
-
6
- import UITableRow from './notTableRow.svelte';
7
-
8
- import {UILinks} from '../../../elements/link';
9
- import {UIButtons} from '../../../elements/button';
10
-
11
- import { onMount , createEventDispatcher} from 'svelte';
12
- let dispatch = createEventDispatcher();
13
-
14
- export let id;
15
-
16
- export let helpers = {};
17
- export let state = {};
18
- export let fields = [];
19
- export let selected = {};
20
- export let items = [];
21
- export let actions = [];
22
- export let links = [];
23
- export let search = '';
24
- export let showSearch = true;
25
- export let showSelect = true;
26
- export let selectAll = false;
27
-
28
- export let getItemId = item => item._id;
29
-
30
- onMount(() => {
31
- if(showSelect){
32
- Stores.get(id).selected.subscribe(value => {
33
- selected = value;
34
- });
35
- }
36
- Stores.get(id).refined.subscribe(value => {
37
- items = value;
38
- if(showSelect){
39
- for(let itemId in selected){
40
- if(! items.some(item => getItemId(item) === itemId)){
41
- delete selected[itemId];
42
- }else{
43
- if(!Object.prototype.hasOwnProperty.call(selected, itemId)){
44
- selected[itemId] = false;
45
- }
46
- }
47
- }
48
- selected = selected;
49
- }
50
- });
51
- Stores.get(id).state.subscribe(value => {
52
- state = value;
53
- });
54
-
55
- });
56
-
57
- function onSearchInput(ev){
58
- try{
59
- let data = ev.currentTarget.value.trim();
60
- dispatch('searchChange', data);
61
- }catch(e){
62
- return;
63
- }
64
- }
65
-
66
- function goPrev(){
67
- dispatch('goToPrevPage');
68
- }
69
-
70
- function goNext(){
71
- dispatch('goToNextPage');
72
- }
73
-
74
- function goTo(e){
75
- e.preventDefault();
76
- let el = e.target;
77
- dispatch('goToPage', parseInt(el.dataset.page));
78
- return false;
79
- }
80
-
81
- function onSelectAll(){
82
- Stores.get(id).selected.update((value)=>{
83
- items.forEach(item => {
84
- value[getItemId(item)] = selectAll;
85
- });
86
- return value;
87
- });
88
- }
89
-
2
+ import { LOCALE } from "../../../locale";
3
+
4
+ import * as Stores from "./stores.js";
5
+
6
+ import UITableRow from "./notTableRow.svelte";
7
+
8
+ import { UILinks } from "../../../elements/link";
9
+ import { UIButtons } from "../../../elements/button";
10
+
11
+ import { onMount, createEventDispatcher } from "svelte";
12
+ let dispatch = createEventDispatcher();
13
+
14
+ export let id;
15
+
16
+ export let filterUI;
17
+
18
+ export let helpers = {};
19
+ export let state = {};
20
+ export let filter = {};
21
+ export let fields = [];
22
+ export let selected = {};
23
+ export let items = [];
24
+ export let actions = [];
25
+ export let links = [];
26
+ export let search = "";
27
+ export let showSearch = true;
28
+ export let showSelect = true;
29
+ export let selectAll = false;
30
+
31
+ export let getItemId = (item) => item._id;
32
+
33
+ onMount(() => {
34
+ if (showSelect) {
35
+ Stores.get(id).selected.subscribe((value) => {
36
+ selected = value;
37
+ });
38
+ }
39
+ Stores.get(id).refined.subscribe((value) => {
40
+ items = value;
41
+ if (showSelect) {
42
+ for (let itemId in selected) {
43
+ if (!items.some((item) => getItemId(item) === itemId)) {
44
+ delete selected[itemId];
45
+ } else {
46
+ if (
47
+ !Object.prototype.hasOwnProperty.call(
48
+ selected,
49
+ itemId
50
+ )
51
+ ) {
52
+ selected[itemId] = false;
53
+ }
54
+ }
55
+ }
56
+ selected = selected;
57
+ }
58
+ });
59
+ Stores.get(id).state.subscribe((value) => {
60
+ state = value;
61
+ });
62
+ });
63
+
64
+ function onSearchInput(ev) {
65
+ try {
66
+ let data = ev.currentTarget.value.trim();
67
+ dispatch("searchChange", data);
68
+ } catch (e) {
69
+ return;
70
+ }
71
+ }
72
+
73
+ function onFilterChange({ detail }) {
74
+ try {
75
+ dispatch("filterChange", detail);
76
+ } catch (e) {
77
+ return;
78
+ }
79
+ }
80
+
81
+ function goPrev() {
82
+ dispatch("goToPrevPage");
83
+ }
84
+
85
+ function goNext() {
86
+ dispatch("goToNextPage");
87
+ }
88
+
89
+ function goTo(e) {
90
+ e.preventDefault();
91
+ let el = e.target;
92
+ dispatch("goToPage", parseInt(el.dataset.page));
93
+ return false;
94
+ }
95
+
96
+ function onSelectAll() {
97
+ Stores.get(id).selected.update((value) => {
98
+ items.forEach((item) => {
99
+ value[getItemId(item)] = selectAll;
100
+ });
101
+ return value;
102
+ });
103
+ }
90
104
  </script>
91
105
 
92
106
  {#if links.length}
93
- <div class="field is-grouped">
94
- <UILinks values={links} />
95
- </div>
107
+ <div class="field is-grouped">
108
+ <UILinks values={links} />
109
+ </div>
96
110
  {/if}
97
111
  {#if actions.length}
98
- <div class="field is-grouped">
99
- <UIButtons values={actions} />
100
- </div>
112
+ <div class="field is-grouped">
113
+ <UIButtons values={actions} />
114
+ </div>
101
115
  {/if}
102
- {#if showSearch }
103
- <div class="field">
104
- <div class="control">
105
- <input class="input" type="text" placeholder="Поиск" bind:value="{search}" on:input={onSearchInput}>
106
- </div>
107
- </div>
116
+ {#if showSearch}
117
+ {#if filterUI}
118
+ <svelte:component
119
+ this={filterUI}
120
+ bind:filter
121
+ on:change={onFilterChange}
122
+ />
123
+ {:else}
124
+ <div class="field">
125
+ <div class="control">
126
+ <input
127
+ class="input"
128
+ type="text"
129
+ placeholder="Поиск"
130
+ bind:value={search}
131
+ on:input={onSearchInput}
132
+ />
133
+ </div>
134
+ </div>
135
+ {/if}
108
136
  {/if}
109
137
  <table class="table">
110
- <thead>
111
- {#if showSelect }
112
- <th><input type="checkbox" id="table-row-select-page" bind:checked={selectAll} placeholder="" name="row_selected_all" on:change={onSelectAll} /></th>
113
- {/if}
114
- {#each fields as field}
115
- <th class="{field.hideOnMobile?'is-hidden-touch':''}">{$LOCALE[field.title]}</th>
116
- {/each}
117
- </thead>
118
- <tbody>
119
- {#each items as item (item._id)}
120
- <UITableRow {id} {item} {fields} {helpers} {showSelect} {getItemId} on:rowSelectChange />
121
- {/each}
122
- </tbody>
138
+ <thead>
139
+ {#if showSelect}
140
+ <th
141
+ ><input
142
+ type="checkbox"
143
+ id="table-row-select-page"
144
+ bind:checked={selectAll}
145
+ placeholder=""
146
+ name="row_selected_all"
147
+ on:change={onSelectAll}
148
+ /></th
149
+ >
150
+ {/if}
151
+ {#each fields as field}
152
+ <th class={field.hideOnMobile ? "is-hidden-touch" : ""}
153
+ >{$LOCALE[field.title]}</th
154
+ >
155
+ {/each}
156
+ </thead>
157
+ <tbody>
158
+ {#each items as item (item._id)}
159
+ <UITableRow
160
+ {id}
161
+ {item}
162
+ {fields}
163
+ {helpers}
164
+ {showSelect}
165
+ {getItemId}
166
+ on:rowSelectChange
167
+ />
168
+ {/each}
169
+ </tbody>
123
170
  </table>
124
171
  <nav class="pagination is-centered" aria-label="pagination">
125
- <a href class="pagination-previous" on:click={goPrev}>Назад</a>
126
- <a href class="pagination-next" on:click={goNext}>Вперед</a>
127
- <ul class="pagination-list">
128
- {#if state.pagination && state.pagination.pages && state.pagination.pages.list }
129
- {#each state.pagination.pages.list as page}
130
- <li>
131
- {#if page.active}
132
- <a href class="pagination-link is-current" aria-label="Страница {page.index}" aria-current="page">{page.index + 1}</a>
133
- {:else}
134
- <a href class="pagination-link" aria-label="Страница {page.index}" data-page="{page.index}" on:click={goTo}>{page.index + 1}</a>
135
- {/if}
136
- </li>
137
- {/each}
138
- {/if}
139
- </ul>
172
+ <a href class="pagination-previous" on:click={goPrev}>Назад</a>
173
+ <a href class="pagination-next" on:click={goNext}>Вперед</a>
174
+ <ul class="pagination-list">
175
+ {#if state.pagination && state.pagination.pages && state.pagination.pages.list}
176
+ {#each state.pagination.pages.list as page}
177
+ <li>
178
+ {#if page.active}
179
+ <a
180
+ href
181
+ class="pagination-link is-current"
182
+ aria-label="Страница {page.index}"
183
+ aria-current="page">{page.index + 1}</a
184
+ >
185
+ {:else}
186
+ <a
187
+ href
188
+ class="pagination-link"
189
+ aria-label="Страница {page.index}"
190
+ data-page={page.index}
191
+ on:click={goTo}>{page.index + 1}</a
192
+ >
193
+ {/if}
194
+ </li>
195
+ {/each}
196
+ {/if}
197
+ </ul>
140
198
  </nav>
@@ -0,0 +1,4 @@
1
+ <script>
2
+ export let filter = {};
3
+ //some filter UI and logic
4
+ </script>
@@ -42,6 +42,7 @@ export default class CRUDActionList {
42
42
  getItemId: undefined,
43
43
  idField: undefined,
44
44
  preload: {},
45
+ filterUI: controller.getOptions(`${ACTION}.filterUI`),
45
46
  pager: { size: 50, page: 0 },
46
47
  sorter: {
47
48
  id: -1,