@geode/opengeodeweb-front 9.10.0-rc.2 → 9.11.0-rc.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.
|
@@ -66,38 +66,75 @@
|
|
|
66
66
|
const allowed_objects = ref({})
|
|
67
67
|
const toggle_loading = useToggle(loading)
|
|
68
68
|
|
|
69
|
+
function select_geode_object(object_map) {
|
|
70
|
+
const object_keys = Object.keys(object_map)
|
|
71
|
+
if (!object_keys.length) {
|
|
72
|
+
return undefined
|
|
73
|
+
}
|
|
74
|
+
if (
|
|
75
|
+
object_keys.length === 1 &&
|
|
76
|
+
object_map[object_keys[0]].is_loadable > 0
|
|
77
|
+
) {
|
|
78
|
+
return object_keys[0]
|
|
79
|
+
}
|
|
80
|
+
const highest_load_score = Math.max(
|
|
81
|
+
...object_keys.map((key) => object_map[key].is_loadable),
|
|
82
|
+
)
|
|
83
|
+
if (highest_load_score <= 0) {
|
|
84
|
+
return undefined
|
|
85
|
+
}
|
|
86
|
+
const best_score_objects = object_keys.filter(
|
|
87
|
+
(key) => object_map[key].is_loadable === highest_load_score,
|
|
88
|
+
)
|
|
89
|
+
if (best_score_objects.length === 1) {
|
|
90
|
+
return best_score_objects[0]
|
|
91
|
+
}
|
|
92
|
+
const highest_priority = Math.max(
|
|
93
|
+
...best_score_objects.map(
|
|
94
|
+
(key) => object_map[key].object_priority ?? -Infinity,
|
|
95
|
+
),
|
|
96
|
+
)
|
|
97
|
+
const best_priority_objects = best_score_objects.filter(
|
|
98
|
+
(key) => object_map[key].object_priority === highest_priority,
|
|
99
|
+
)
|
|
100
|
+
if (highest_priority !== -Infinity && best_priority_objects.length === 1) {
|
|
101
|
+
return best_priority_objects[0]
|
|
102
|
+
}
|
|
103
|
+
return undefined
|
|
104
|
+
}
|
|
105
|
+
|
|
69
106
|
async function get_allowed_objects() {
|
|
70
107
|
toggle_loading()
|
|
71
108
|
allowed_objects.value = {}
|
|
72
|
-
|
|
73
|
-
for (const filename of filenames) {
|
|
109
|
+
const promise_array = filenames.map((filename) => {
|
|
74
110
|
const params = { filename, supported_feature }
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
111
|
+
return api_fetch({ schema, params })
|
|
112
|
+
})
|
|
78
113
|
const responses = await Promise.all(promise_array)
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
(i) => !values.some((j) => !Object.keys(j).includes(i)),
|
|
114
|
+
const allowed_objects_list = responses.map(
|
|
115
|
+
(response) => response.data.value.allowed_objects,
|
|
116
|
+
)
|
|
117
|
+
const all_keys = [...new Set(allowed_objects_list.flatMap(Object.keys))]
|
|
118
|
+
const common_keys = all_keys.filter((key) =>
|
|
119
|
+
allowed_objects_list.every((obj) => key in obj),
|
|
86
120
|
)
|
|
87
|
-
|
|
121
|
+
const final_object = {}
|
|
88
122
|
for (const key of common_keys) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
123
|
+
const load_scores = allowed_objects_list.map(
|
|
124
|
+
(obj) => obj[key].is_loadable,
|
|
125
|
+
)
|
|
126
|
+
const priorities = allowed_objects_list
|
|
127
|
+
.map((obj) => obj[key].object_priority)
|
|
128
|
+
.filter((p) => p !== undefined && p !== null)
|
|
129
|
+
final_object[key] = { is_loadable: Math.min(...load_scores) }
|
|
130
|
+
if (priorities.length) {
|
|
131
|
+
final_object[key].object_priority = Math.max(...priorities)
|
|
95
132
|
}
|
|
96
133
|
}
|
|
97
|
-
|
|
98
134
|
allowed_objects.value = final_object
|
|
99
|
-
|
|
100
|
-
|
|
135
|
+
const selected_object = select_geode_object(final_object)
|
|
136
|
+
if (selected_object) {
|
|
137
|
+
set_geode_object(selected_object)
|
|
101
138
|
}
|
|
102
139
|
toggle_loading()
|
|
103
140
|
}
|
package/package.json
CHANGED
|
@@ -83,4 +83,33 @@ describe("ObjectSelector.vue", async () => {
|
|
|
83
83
|
input_geode_object: geode_object_1,
|
|
84
84
|
})
|
|
85
85
|
})
|
|
86
|
+
|
|
87
|
+
test(`test object_priority when is_loadable scores equal`, async () => {
|
|
88
|
+
var response = { allowed_objects: {} }
|
|
89
|
+
const geode_object_1 = "BRep"
|
|
90
|
+
const geode_object_2 = "EdgedCurve3D"
|
|
91
|
+
response["allowed_objects"][geode_object_1] = {
|
|
92
|
+
is_loadable: 1.0,
|
|
93
|
+
object_priority: 2,
|
|
94
|
+
}
|
|
95
|
+
response["allowed_objects"][geode_object_2] = {
|
|
96
|
+
is_loadable: 1.0,
|
|
97
|
+
object_priority: 1,
|
|
98
|
+
}
|
|
99
|
+
registerEndpoint(allowed_objects.$id, {
|
|
100
|
+
method: allowed_objects.methods[0],
|
|
101
|
+
handler: () => response,
|
|
102
|
+
})
|
|
103
|
+
const wrapper = await mountSuspended(ObjectSelector, {
|
|
104
|
+
global: {
|
|
105
|
+
plugins: [vuetify, pinia],
|
|
106
|
+
},
|
|
107
|
+
props: { filenames: ["test.toto"], supported_feature: "test" },
|
|
108
|
+
})
|
|
109
|
+
expect(wrapper.emitted()).toHaveProperty("update_values")
|
|
110
|
+
expect(wrapper.emitted().update_values).toHaveLength(1)
|
|
111
|
+
expect(wrapper.emitted().update_values[0][0]).toEqual({
|
|
112
|
+
input_geode_object: geode_object_1,
|
|
113
|
+
})
|
|
114
|
+
})
|
|
86
115
|
})
|