Skip to content

Commit 4cf6ad9

Browse files
committed
VueTypedUIRoot ($UI)
1 parent 07174e5 commit 4cf6ad9

File tree

13 files changed

+149
-121
lines changed

13 files changed

+149
-121
lines changed

demo/src/settings-page/index.html

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
1-
<ui-modal v-on:approved="save" v-on:denied="reset">
1+
<ui-modal v-on:approve="save" v-on:deny="reset" :closable="false">
22

33
<span slot="header"><i class="icon setting"></i> Settings</span>
44
<ui-form>
5-
<ui-dropdown v-model="value.dateFormat" label="Date Format" kind="inline">
5+
<ui-dropdown v-model="dateFormat" label="Date Format" kind="inline">
66
<ui-dropdown-item v-for="f in dateFormats" :value="f">{{f}}</ui-dropdown-item>
77
</ui-dropdown>
8-
<ui-dropdown v-model="value.timeFormat" label="Time Format" kind="inline">
8+
<ui-dropdown v-model="timeFormat" label="Time Format" kind="inline">
99
<ui-dropdown-item v-for="f in timeFormats" :value="f">{{f}}</ui-dropdown-item>
1010
</ui-dropdown>
1111
<ui-segment>
1212
<ui-h4>Numeric Settings</ui-h4>
13-
<numeric-settings-page v-model="value.numeric"></numeric-settings-page>
13+
<ui-fields-group :wide="2">
14+
<ui-field>
15+
<ui-input kind="inline" label="Group Separator" v-model="groupSeparator"></ui-input>
16+
<ui-input kind="inline" label="Decimal Separator" v-model="decimalSeparator"></ui-input>
17+
<ui-input kind="inline" label="Decimal Places" v-model="decimalPlaces"></ui-input>
18+
</ui-field>
19+
<ui-field>
20+
<ui-input kind="inline" label="Sign" v-model="sign"></ui-input>
21+
<ui-input kind="inline" label="Min" v-model="min"></ui-input>
22+
<ui-input kind="inline" label="Max" v-model="max"></ui-input>
23+
</ui-field>
24+
</ui-fields-group>
1425
</ui-segment>
1526
</ui-form>
1627
<span slot="actions">

demo/src/settings-page/index.ts

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,64 @@
11
import * as Vue from 'vue';
22
import { Component } from 'vue-typed';
33
import { DateFormat, TimeFormat } from '../../../lib/types';
4-
import { NumericSettingsPage } from './numeric-settings-page';
4+
import { NumericSettings } from '../../../lib/settings';
55
import * as _ from "lodash"
66

77
@Component({
8-
template: require('./index.html'),
9-
components: {
10-
'numeric-settings-page': NumericSettingsPage
11-
}
8+
template: require('./index.html')
129
})
1310
export class SettingsPage extends Vue {
14-
15-
dateFormats = ['MM/DD/YYYY' , 'DD/MM/YYYY' , 'MMM DD, YYYY' , 'MMMM DD, YYYY']
16-
timeFormats = ['HH:mm' , 'hh:mm A' , 'HH:mm:SS']
11+
12+
dateFormats = ['MM/DD/YYYY', 'DD/MM/YYYY', 'MMM DD, YYYY', 'MMMM DD, YYYY']
13+
timeFormats = ['HH:mm', 'hh:mm A', 'HH:mm:SS']
1714

1815
value = {}
16+
dateFormat : DateFormat = undefined
17+
timeFormat : TimeFormat = undefined
18+
19+
groupSeparator = undefined
20+
decimalSeparator = undefined
21+
decimalPlaces = undefined
22+
sign = undefined
23+
signPos : 'left' | 'right'= undefined
24+
min = undefined
25+
max = undefined
1926

20-
created() {
27+
created() {
2128
this.reset()
2229
}
2330

24-
save() {
25-
Vue.set(this.$ui, '$settings', this.value)
31+
save(e) {
32+
33+
if (this.decimalSeparator == this.groupSeparator) {
34+
e.result = false
35+
this.$ui.alert('Numeric Settings Failed', 'Decimal separator can not be same as group separator.')
36+
return
37+
}
38+
39+
let $set = this.$UI.$settings
40+
$set.dateFormat = this.dateFormat
41+
$set.timeFormat = this.timeFormat
42+
$set.numeric.decimalPlaces = this.decimalPlaces
43+
$set.numeric.decimalSeparator = this.decimalSeparator
44+
$set.numeric.groupSeparator = this.groupSeparator
45+
$set.numeric.sign = this.sign
46+
$set.numeric.signPos = this.signPos
47+
$set.numeric.min = this.min
48+
$set.numeric.max = this.max
2649
}
2750

2851
reset() {
29-
// settings should not reactive before applied
30-
this.value = _.cloneDeep(this.$ui.$settings)
52+
let $set = this.$UI.$settings
53+
this.dateFormat = $set.dateFormat
54+
this.timeFormat = $set.timeFormat
55+
this.decimalPlaces = $set.numeric.decimalPlaces
56+
this.decimalSeparator = $set.numeric.decimalSeparator
57+
this.groupSeparator = $set.numeric.groupSeparator
58+
this.sign = $set.numeric.sign
59+
this.signPos = $set.numeric.signPos
60+
this.min = $set.numeric.min
61+
this.max = $set.numeric.max
3162
}
3263

3364

demo/src/settings-page/numeric-settings-page.html

Lines changed: 0 additions & 14 deletions
This file was deleted.

demo/src/settings-page/numeric-settings-page.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

dist/vue-typed-ui.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,21 @@ declare namespace VueTypedUI {
1515

1616
declare class VueTypedUI extends VueTypedUIMethods {
1717
static install: Vue.PluginFunction<VueTypedUI.Options>
18-
$settings: VueTypedUI.Settings
1918

2019
createValidationRule(name: string, rule: Function)
2120
alert: modules.Alert
2221
toast: modules.Toastr
2322
focus: modules.Focus
23+
}
2424

25+
declare class VueTypedUIRoot {
26+
$settings: VueTypedUI.Settings
2527
}
2628

2729
declare module "vue/types/vue" {
2830
interface Vue {
2931
$ui: VueTypedUI
32+
$UI: VueTypedUIRoot
3033
}
3134
}
3235

dist/vue-typed-ui.js

Lines changed: 60 additions & 48 deletions
Large diffs are not rendered by default.

src/components/form-inputs/calendar/date/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ export class Date extends _DateBase {
1111
type = 'date'
1212
icon = 'calendar'
1313

14-
@Watch('$ui.$settings.dateFormat')
14+
@Watch('$UI.$settings.dateFormat')
1515
onSettingsChanged(val) {
1616
$(this.$el)['calendar']('destroy');
1717
this.setupUi();
1818
}
1919

2020
buildOptions(options) {
2121

22-
var format = (!this.format || this.format == 'default') ? this.$ui.$settings.dateFormat : this.format
22+
var format = (!this.format || this.format == 'default') ? this.$UI.$settings.dateFormat : this.format
2323

2424
Object.assign(options, {
2525
formatter: {

src/components/form-inputs/calendar/datetime/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class DateTime extends _DatetimeBase {
1212
type = 'datetime'
1313
icon = 'calendar'
1414

15-
@Watch('$ui.$settings')
15+
@Watch('$UI.$settings')
1616
onSettingsChanged(val: Settings, old: Settings) {
1717
if (old.dateFormat === val.dateFormat && old.timeFormat === val.timeFormat)
1818
return;
@@ -23,7 +23,7 @@ export class DateTime extends _DatetimeBase {
2323

2424
buildOptions(options) {
2525

26-
var format = (!this.format || this.format == 'default') ? this.$ui.$settings.dateFormat + ' ' + this.$ui.$settings.timeFormat : this.format
26+
var format = (!this.format || this.format == 'default') ? this.$UI.$settings.dateFormat + ' ' + this.$UI.$settings.timeFormat : this.format
2727

2828
Object.assign(options, {
2929
formatter: {

src/components/form-inputs/calendar/time/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ export class Time extends _TimeBase {
1111
type = 'time'
1212
icon = 'time'
1313

14-
@Watch('$ui.$settings.timeFormat')
14+
@Watch('$UI.$settings.timeFormat')
1515
onSettingsChanged(val) {
1616
$(this.$el)['calendar']('destroy');
1717
this.setupUi();
1818
}
1919

2020
buildOptions(options) {
2121

22-
var format = (!this.format || this.format == 'default') ? this.$ui.$settings.timeFormat : this.format
22+
var format = (!this.format || this.format == 'default') ? this.$UI.$settings.timeFormat : this.format
2323

2424
Object.assign(options, {
2525
formatter: {

src/components/form-inputs/currency/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ export class Currency extends _CurrencyBase {
1515
}
1616

1717
buildOptions(options) {
18-
let signPos : string = Util.pickNonEmpty(this.signPos, this.$ui.$settings.numeric.signPos)
19-
let sign : string = Util.pickNonEmpty(this.sign, this.$ui.$settings.numeric.sign)
18+
let signPos : string = Util.pickNonEmpty(this.signPos, this.$UI.$settings.numeric.signPos)
19+
let sign : string = Util.pickNonEmpty(this.sign, this.$UI.$settings.numeric.sign)
2020
return Object.assign(options, Util.decodeCurrencyProperties(sign, signPos))
2121
}
2222

0 commit comments

Comments
 (0)