:zap: [Enhance] Remove endpoint from available models select when click remove button
Browse files- storages/endpoint_storage.js +16 -10
storages/endpoint_storage.js
CHANGED
@@ -105,12 +105,11 @@ class EndpointStorage {
|
|
105 |
endpoint_and_api_key_items.hide();
|
106 |
}
|
107 |
bind_endpoint_and_api_key_buttons(endpoint_and_api_key_item) {
|
108 |
-
let self = this;
|
109 |
// console.log("endpoint_and_api_key_item:", endpoint_and_api_key_item);
|
110 |
let endpoint_submit_button = endpoint_and_api_key_item.find(
|
111 |
".submit-endpoint-button"
|
112 |
);
|
113 |
-
endpoint_submit_button.click(
|
114 |
let endpoint_input =
|
115 |
endpoint_and_api_key_item.find(".endpoint-input");
|
116 |
let endpoint_input_value = endpoint_input.val().trim();
|
@@ -122,7 +121,7 @@ class EndpointStorage {
|
|
122 |
console.log("Endpoint is empty.");
|
123 |
return;
|
124 |
} else {
|
125 |
-
|
126 |
index: endpoint_input_value,
|
127 |
endpoint: endpoint_input_value,
|
128 |
api_key: api_key_input_value,
|
@@ -130,28 +129,35 @@ class EndpointStorage {
|
|
130 |
});
|
131 |
console.log(`new_endpoint: ${endpoint_input_value}`);
|
132 |
}
|
133 |
-
|
134 |
});
|
135 |
|
136 |
let remove_endpoint_buttons = endpoint_and_api_key_item.find(
|
137 |
".remove-endpoint-button"
|
138 |
);
|
139 |
-
remove_endpoint_buttons.click(
|
140 |
let endpoint_input =
|
141 |
endpoint_and_api_key_item.find(".endpoint-input");
|
142 |
let endpoint_input_value = endpoint_input.val();
|
143 |
endpoint_and_api_key_item.remove();
|
144 |
if (
|
145 |
endpoint_input_value.trim() === "" ||
|
146 |
-
|
147 |
) {
|
148 |
console.log("Endpoint not in endpoints");
|
149 |
} else {
|
150 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
}
|
152 |
-
console.log(`remove endpoint: ${endpoint_input_value}`);
|
153 |
-
|
154 |
-
// TODO: remove models of current endpoint from available_models_select
|
155 |
});
|
156 |
}
|
157 |
fetch_available_models(endpoint) {
|
|
|
105 |
endpoint_and_api_key_items.hide();
|
106 |
}
|
107 |
bind_endpoint_and_api_key_buttons(endpoint_and_api_key_item) {
|
|
|
108 |
// console.log("endpoint_and_api_key_item:", endpoint_and_api_key_item);
|
109 |
let endpoint_submit_button = endpoint_and_api_key_item.find(
|
110 |
".submit-endpoint-button"
|
111 |
);
|
112 |
+
endpoint_submit_button.click(() => {
|
113 |
let endpoint_input =
|
114 |
endpoint_and_api_key_item.find(".endpoint-input");
|
115 |
let endpoint_input_value = endpoint_input.val().trim();
|
|
|
121 |
console.log("Endpoint is empty.");
|
122 |
return;
|
123 |
} else {
|
124 |
+
this.db.endpoints.put({
|
125 |
index: endpoint_input_value,
|
126 |
endpoint: endpoint_input_value,
|
127 |
api_key: api_key_input_value,
|
|
|
129 |
});
|
130 |
console.log(`new_endpoint: ${endpoint_input_value}`);
|
131 |
}
|
132 |
+
this.fill_available_models_select(endpoint_input_value);
|
133 |
});
|
134 |
|
135 |
let remove_endpoint_buttons = endpoint_and_api_key_item.find(
|
136 |
".remove-endpoint-button"
|
137 |
);
|
138 |
+
remove_endpoint_buttons.click(() => {
|
139 |
let endpoint_input =
|
140 |
endpoint_and_api_key_item.find(".endpoint-input");
|
141 |
let endpoint_input_value = endpoint_input.val();
|
142 |
endpoint_and_api_key_item.remove();
|
143 |
if (
|
144 |
endpoint_input_value.trim() === "" ||
|
145 |
+
this.db.endpoints.get(endpoint_input_value) === undefined
|
146 |
) {
|
147 |
console.log("Endpoint not in endpoints");
|
148 |
} else {
|
149 |
+
this.db.endpoints.delete(endpoint_input_value);
|
150 |
+
// remove models of current endpoint from available_models_select
|
151 |
+
let available_models_select = $("#available-models-select");
|
152 |
+
let model_value = this.construct_model_name_and_value(
|
153 |
+
endpoint_input_value,
|
154 |
+
""
|
155 |
+
)[1];
|
156 |
+
available_models_select
|
157 |
+
.find(`option[value^="${model_value}"]`)
|
158 |
+
.remove();
|
159 |
+
console.log(`remove endpoint: ${endpoint_input_value}`);
|
160 |
}
|
|
|
|
|
|
|
161 |
});
|
162 |
}
|
163 |
fetch_available_models(endpoint) {
|