@cybertale/form 0.1.2 → 0.1.4

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.2",
3
+ "version": "0.1.4",
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",
@@ -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,23 +43,29 @@ 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
- return this.object.Stats[tag]?.Data ?? ''
49
+ if (this.object.Stats[tag]) {
50
+ return this.object.Stats[tag].Data
51
+ }
52
+ return ''
49
53
  }
50
54
 
51
55
  async created() {
52
56
  await this.fetchOptions();
57
+ this.loading = false
53
58
  }
54
59
 
55
60
  // Extract the logic for fetching options data into a separate method
56
61
  async fetchOptions() {
62
+ console.log(this.object.Stats)
57
63
  try {
58
64
  const parsedObject: { link?: string } = JSON.parse(this.object.Stats[this.statTypeEnum.ItemList].Data)[0];
59
65
  if (parsedObject.link) {
60
- const response = await http.get(parsedObject.link + '/' + this.object.Stats[this.statTypeEnum.Name].Data);
61
- this.options = response.data;
62
- 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)
63
69
  } else {
64
70
  this.options = JSON.parse(this.object.Stats[this.statTypeEnum.ItemList].Data);
65
71
  }
@@ -70,7 +76,7 @@ export default class DataListComponent extends Vue {
70
76
 
71
77
  getValue (statEnum: number, indexStatTypeEnum = StatTypeEnum.Option) : string {
72
78
  if (this.object.Stats[statEnum]) {
73
- if (this.object.Stats[indexStatTypeEnum] && this.object.Stats[statEnum] && isValidJSON(this.object.Stats[statEnum].Data)) {
79
+ if (this.object.Stats[indexStatTypeEnum] && this.object.Stats[statEnum] && this.isJSON(this.object.Stats[statEnum].Data)) {
74
80
  const data = JSON.parse(this.object.Stats[statEnum].Data)
75
81
  return data[Number(this.object.Stats[indexStatTypeEnum].Data)]
76
82
  } else {
@@ -82,11 +88,20 @@ export default class DataListComponent extends Vue {
82
88
 
83
89
  get valueName (): string {
84
90
  const temp = this.options.find((option: any) => option.id === this.getValue(StatTypeEnum.Value, StatTypeEnum.ValueIndices))
85
- return temp?.name ?? this.getValue(StatTypeEnum.Value, StatTypeEnum.ValueIndices)
91
+ if (!temp) { return this.getValue(StatTypeEnum.Value, StatTypeEnum.ValueIndices) }
92
+ return temp?.name
86
93
  }
87
94
 
88
95
  attributeCheck (statType : number) : boolean | string {
89
- return this.object.Stats[statType]?.Data ?? false
96
+ if (this.object.Stats[statType] === undefined) { return false }
97
+ if (this.object.Stats[statType].Data === '') { return false }
98
+ return this.object.Stats[statType].Data
99
+ }
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
90
105
  }
91
106
 
92
107
  validate () : string {
@@ -103,21 +118,23 @@ export default class DataListComponent extends Vue {
103
118
  this.regionType.RegionTypes[object.Region].ObjectTypes[object.ObjectEnum].ChooseSubType(object, value)
104
119
  }
105
120
 
106
- isSelected (id : string) : boolean { //previously check
107
- return this.object.Stats[this.statTypeEnum.Value]?.Data === id.toString()
121
+ check (id : string) : boolean {
122
+ if (this.object.Stats[this.statTypeEnum.Value] === undefined || id === undefined) { return false }
123
+ return this.object.Stats[this.statTypeEnum.Value].Data === id.toString()
108
124
  }
109
125
 
110
- }
111
-
112
- // Utility function to check if a string is valid JSON
113
- function isValidJSON(str: string): boolean {
114
- try {
115
- JSON.parse(str);
116
- return true;
117
- } catch (e) {
118
- return false;
126
+ isJSON (str: string): boolean {
127
+ let temp = null
128
+ try {
129
+ temp = JSON.parse(str)
130
+ } catch (e) {
131
+ return false
132
+ }
133
+ return Array.isArray(temp)
119
134
  }
135
+
120
136
  }
137
+
121
138
  </script>
122
139
  <!-- Add "scoped" attribute to limit CSS to this component only -->
123
140
  <style scoped>