@cybertale/form 0.1.3 → 0.1.5

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": "@cybertale/form",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "ECS interface for Web Development, CyberTale edition.",
5
5
  "author": "Joso Marich <jspmari@proton.me>",
6
6
  "license": "GPL-3.0-only",
@@ -1,7 +1,7 @@
1
1
  <template>
2
2
  <div :class="object?.Stats[statTypeEnum.Design].Data">
3
3
  <input class="form-check-input mt-0" type="checkbox"
4
- :checked="!!object?.Stats[statTypeEnum.Value].Data"
4
+ :checked="getValue(statTypeEnum.Value, statTypeEnum.ValueIndices)"
5
5
  :id="object?.Stats[statTypeEnum.Tag].Data"
6
6
  :required="attributeCheck(statTypeEnum.Required)"
7
7
  :disabled="attributeCheck(statTypeEnum.Disabled)"
@@ -42,6 +42,28 @@ export default class CheckBoxComponent extends Vue {
42
42
  return ''
43
43
  }
44
44
 
45
+ getValue (statEnum: number, indexStatTypeEnum = StatTypeEnum.Option) : string {
46
+ if (this.object.Stats[statEnum]) {
47
+ if (this.object.Stats[indexStatTypeEnum] && this.object.Stats[statEnum] && this.isJSON(this.object.Stats[statEnum].Data)) {
48
+ const data = JSON.parse(this.object.Stats[statEnum].Data)
49
+ return data[Number(this.object.Stats[indexStatTypeEnum].Data)]
50
+ } else {
51
+ return this.object.Stats[statEnum].Data
52
+ }
53
+ }
54
+ return ''
55
+ }
56
+
57
+ isJSON (str: string): boolean {
58
+ let temp = null
59
+ try {
60
+ temp = JSON.parse(str)
61
+ } catch (e) {
62
+ return false
63
+ }
64
+ return Array.isArray(temp)
65
+ }
66
+
45
67
  validate () : string {
46
68
  if (this.object.Stats[this.statTypeEnum.IsValid] === undefined) { return '' }
47
69
  if (this.object.Stats[this.statTypeEnum.IsValid].Data === '') { return '' }
@@ -2,7 +2,7 @@
2
2
  <input class="form-control" :list="object.Stats[statTypeEnum.BelongsTo].Data"
3
3
  :class="returnIfExists(statTypeEnum.Design) + ' ' + validate()"
4
4
  :required="attributeCheck(statTypeEnum.Required)"
5
- :disabled="attributeCheck(statTypeEnum.Disabled)"
5
+ :disabled="disabledCheck(statTypeEnum.Disabled)"
6
6
  :type="returnIfExists(statTypeEnum.ElementType)"
7
7
  :value="`${object?.Stats[statTypeEnum.Value].Data !== null ? object.Stats[statTypeEnum.Value].Data.name === undefined ? valueName : object.Stats[statTypeEnum.Value].Data.name : ''}`"
8
8
  :placeholder="returnIfExists(statTypeEnum.Placeholder)"
@@ -43,6 +43,7 @@ export default class DataListComponent extends Vue {
43
43
  object!: ObjectTemplate
44
44
  displayOptions = false
45
45
  options: Option[] = []
46
+ loading = true
46
47
 
47
48
  returnIfExists (tag: number): string {
48
49
  if (this.object.Stats[tag]) {
@@ -53,16 +54,18 @@ export default class DataListComponent extends Vue {
53
54
 
54
55
  async created() {
55
56
  await this.fetchOptions();
57
+ this.loading = false
56
58
  }
57
59
 
58
60
  // Extract the logic for fetching options data into a separate method
59
61
  async fetchOptions() {
62
+ console.log(this.object.Stats)
60
63
  try {
61
64
  const parsedObject: { link?: string } = JSON.parse(this.object.Stats[this.statTypeEnum.ItemList].Data)[0];
62
65
  if (parsedObject.link) {
63
- const response = await http.get(parsedObject.link + '/' + this.object.Stats[this.statTypeEnum.Name].Data);
64
- this.options = response.data;
65
- this.displayOptions = true;
66
+ const response = await http.get(parsedObject.link + '/' + this.object.Stats[this.statTypeEnum.Name].Data)
67
+ this.options = response.data
68
+ this.object.Stats[this.statTypeEnum.ItemList].Data = JSON.stringify(response.data)
66
69
  } else {
67
70
  this.options = JSON.parse(this.object.Stats[this.statTypeEnum.ItemList].Data);
68
71
  }
@@ -95,6 +98,12 @@ export default class DataListComponent extends Vue {
95
98
  return this.object.Stats[statType].Data
96
99
  }
97
100
 
101
+ disabledCheck (statType : number) : boolean | string {
102
+ if (this.object.Stats[statType] === undefined) { return (false || this.loading) }
103
+ if (this.object.Stats[statType].Data === '') { return (false || this.loading) }
104
+ return this.object.Stats[statType].Data
105
+ }
106
+
98
107
  validate () : string {
99
108
  if (this.object.Stats[this.statTypeEnum.IsValid] === undefined) { return '' }
100
109
  if (this.object.Stats[this.statTypeEnum.IsValid].Data === '') { return '' }