|
95 | 95 | $term = $request->term;
|
96 | 96 | $results = App\EventName::select('name as value', 'code as key')
|
97 | 97 | ->where([
|
98 |
| - ['name', 'like', "$term%"], |
99 | 98 | ['is_task', $is_task],
|
100 | 99 | ]);
|
101 | 100 | if ($request->filled('category')) {
|
102 | 101 | $results->whereRaw('ifnull(category, ?) = ?', [$request->category, $request->category]);
|
103 | 102 | }
|
104 |
| - |
105 |
| - return $results->take(10)->get(); |
| 103 | + $match_list = Array(); |
| 104 | + foreach($results->get() as $item) { |
| 105 | + if(str_starts_with(strtolower(__($item["value"])), strtolower($term)) or str_starts_with(strtolower($item["key"]), strtolower($term)) ){ |
| 106 | + $match_item = ["key" => $item["key"], "value" => __($item["value"])]; |
| 107 | + array_push($match_list, $match_item); |
| 108 | + } |
| 109 | + } |
| 110 | + return $match_list; |
106 | 111 | });
|
107 | 112 |
|
108 | 113 | Route::get('classifier-type/autocomplete/{main_display}', function (Request $request, $main_display) {
|
109 | 114 | $term = $request->input('term');
|
110 | 115 | $results = App\ClassifierType::select('type as value', 'code as key')
|
111 |
| - ->where('type', 'like', "$term%") |
112 | 116 | ->where('main_display', $main_display)
|
113 | 117 | ->orderBy('type');
|
114 |
| - |
115 |
| - return $results->take(10)->get(); |
| 118 | + $match_list = Array(); |
| 119 | + foreach($results->get() as $item) { |
| 120 | + if(str_starts_with(strtolower(__($item["value"])), strtolower($term)) or str_starts_with(strtolower($item["key"]), strtolower($term)) ){ |
| 121 | + $match_item = ["key" => $item["key"], "value" => __($item["value"])]; |
| 122 | + array_push($match_list, $match_item); |
| 123 | + } |
| 124 | + } |
| 125 | + return $match_list; |
116 | 126 | });
|
117 | 127 |
|
118 | 128 | Route::get('user/autocomplete', function (Request $request) {
|
|
131 | 141 | ->orWhere('display_name', 'like', "$term")
|
132 | 142 | ->take(10)->get();
|
133 | 143 | if ($list->count() < 5 && $create_option) {
|
134 |
| - $list->push(['label' => "Create $term?", 'key' => 'create', 'value' => $term]); |
| 144 | + $list->push(['label' => __("Create $term?"), 'key' => 'create', 'value' => $term]); |
135 | 145 | }
|
136 | 146 |
|
137 | 147 | return $list;
|
|
140 | 150 | Route::get('role/autocomplete', function (Request $request) {
|
141 | 151 | $term = $request->input('term');
|
142 | 152 |
|
143 |
| - return App\Role::select('name as value', 'code as key', 'shareable') |
144 |
| - ->where('name', 'like', "$term%") |
145 |
| - ->orWhere('code', 'like', "$term%")->get(); |
| 153 | + $full_list = App\Role::select('name as value', 'code as key', 'shareable')->get(); |
| 154 | + $match_list = Array(); |
| 155 | + foreach($full_list as $item) { |
| 156 | + if(str_starts_with(strtolower(__($item["value"])), strtolower($term)) or str_starts_with(strtolower($item["key"]), strtolower($term)) ){ |
| 157 | + $match_item = ["key" => $item["key"], "shareable" => $item["shareable"], "value" => __($item["value"])]; |
| 158 | + array_push($match_list, $match_item); |
| 159 | + } |
| 160 | + } |
| 161 | + return $match_list; |
146 | 162 | });
|
147 | 163 |
|
148 | 164 | Route::get('dbrole/autocomplete', function (Request $request) {
|
149 | 165 | $term = $request->input('term');
|
150 | 166 |
|
151 |
| - return App\Role::select('name as value', 'code as key') |
152 |
| - ->where('name', 'like', "$term%") |
| 167 | + $full_list = App\Role::select('name as value', 'code as key') |
153 | 168 | ->whereIn('code', ['CLI', 'DBA', 'DBRW', 'DBRO'])->get();
|
| 169 | + $match_list = Array(); |
| 170 | + foreach($full_list as $item) { |
| 171 | + if(str_starts_with(strtolower(__($item["value"])), strtolower($term)) or str_starts_with(strtolower($item["key"]), strtolower($term)) ){ |
| 172 | + $match_item = ["key" => $item["key"], "value" => __($item["value"])]; |
| 173 | + array_push($match_list, $match_item); |
| 174 | + } |
| 175 | + } |
| 176 | + return $match_list; |
154 | 177 | });
|
155 | 178 |
|
156 | 179 | Route::get('country/autocomplete', function (Request $request) {
|
157 | 180 | $term = $request->input('term');
|
158 |
| - $list = App\Country::select('name as value', 'iso as key') |
159 |
| - ->where('name', 'like', "$term%") |
160 |
| - ->orWhere('iso', 'like', "$term%")->get(); |
161 |
| - |
162 |
| - return $list; |
| 181 | + $full_list = App\Country::select('name as value', 'iso as key')->get(); |
| 182 | + $match_list = Array(); |
| 183 | + foreach($full_list as $item) { |
| 184 | + if(str_starts_with(strtolower(__($item["value"])), strtolower($term)) or str_starts_with(strtolower($item["key"]), strtolower($term)) ){ |
| 185 | + $match_item = ["key" => $item["key"], "value" => __($item["value"])]; |
| 186 | + array_push($match_list, $match_item); |
| 187 | + } |
| 188 | + } |
| 189 | + return $match_list; |
163 | 190 | });
|
164 | 191 |
|
165 | 192 | Route::get('category/autocomplete', function (Request $request) {
|
166 | 193 | $term = $request->input('term');
|
167 | 194 |
|
168 |
| - return App\Category::select('category as value', 'code as key', 'ref_prefix as prefix') |
169 |
| - ->where('category', 'like', "$term%") |
170 |
| - ->orWhere('code', 'like', "$term%")->get(); |
| 195 | + $full_list = App\Category::select('category as value', 'code as key', 'ref_prefix as prefix')->get(); |
| 196 | + $match_list = Array(); |
| 197 | + foreach($full_list as $item) { |
| 198 | + if(str_starts_with(strtolower(__($item["value"])), strtolower($term)) or str_starts_with(strtolower($item["key"]), strtolower($term)) ){ |
| 199 | + $match_item = ["key" => $item["key"], "prefix" => $item["prefix"], "value" => __($item["value"])]; |
| 200 | + array_push($match_list, $match_item); |
| 201 | + } |
| 202 | + } |
| 203 | + return $match_list; |
171 | 204 | });
|
172 | 205 |
|
173 | 206 | Route::get('type/autocomplete', function (Request $request) {
|
174 | 207 | $term = $request->input('term');
|
175 | 208 |
|
176 |
| - return App\Type::select('type as value', 'code as key') |
177 |
| - ->where('type', 'like', "$term%") |
178 |
| - ->orWhere('code', 'like', "$term%")->get(); |
| 209 | + $full_list = App\Type::select('type as value', 'code as key')->get(); |
| 210 | + $match_list = Array(); |
| 211 | + foreach($full_list as $item) { |
| 212 | + if(str_starts_with(strtolower(__($item["value"])), strtolower($term)) or str_starts_with(strtolower($item["key"]), strtolower($term)) ){ |
| 213 | + $match_item = ["key" => $item["key"], "value" => __($item["value"])]; |
| 214 | + array_push($match_list, $match_item); |
| 215 | + } |
| 216 | + } |
| 217 | + return $match_list; |
179 | 218 | });
|
180 | 219 |
|
181 | 220 | Route::get('classifier/{classifier}/img', fn (App\Classifier $classifier) => response($classifier->img)
|
|
186 | 225 | $list = App\TemplateMember::select('category as value', 'category as key')
|
187 | 226 | ->where('category', 'like', "$term%")->distinct()->get();
|
188 | 227 | if ($list->count() == 0) {
|
189 |
| - $list->push(['label' => "Create $term", 'key' => $term, 'value' => $term]); |
| 228 | + $list->push(['label' => __("Create $term"), 'key' => $term, 'value' => $term]); |
190 | 229 | }
|
191 | 230 |
|
192 | 231 | return $list;
|
|
0 commit comments