Skip to content

Commit 55fd913

Browse files
committed
change series connection dialog to search instead of plain list
1 parent 6f769d5 commit 55fd913

File tree

4 files changed

+99
-55
lines changed

4 files changed

+99
-55
lines changed

classes/OCRestClient/ApiSeriesClient.php

+14-5
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,26 @@ public function setACL($series_id, $acl)
3232
return $result[1] == 200;
3333
}
3434

35-
public function getAll($withacl = false, $onlyWithWriteAccess = false)
35+
public function search($text)
3636
{
37+
if (strlen($text) < 3) {
38+
return false;
39+
}
40+
3741
$params = [
38-
'withacl' => $withacl,
39-
'onlyWithWriteAccess' => $onlyWithWriteAccess,
42+
'filter' => 'textFilter:' . $text,
43+
'limit' => 100,
44+
'offset' => 0,
45+
'withacl' => 'false',
46+
'onlyWithWriteAccess' => 'false'
4047
];
4148

42-
$data = $this->getJSON('?' . http_build_query($params));
49+
$data = $this->getJSON($query = '/?' . http_build_query($params));
50+
4351
$series = [];
52+
4453
if (is_array($data)) foreach ($data as $serie) {
45-
$series[$serie->identifier] = $serie;
54+
$series[$serie->identifier] = $serie->title;
4655
}
4756

4857
return $series;

controllers/ajax.php

+31
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,35 @@ public function getltidata_action($series_id)
191191
];
192192
$this->render_json($result);
193193
}
194+
195+
public function search_series_action()
196+
{
197+
$configs = OCConfig::getBaseServerConf();
198+
$user_series = OCSeminarSeries::getSeriesByUserMemberStatus($GLOBALS['user']->id, 'dozent');
199+
$all_series = [];
200+
$is_admin = $GLOBALS['perm']->have_studip_perm('admin', Context::getId());
201+
202+
// search on every oc-server for the series with this name
203+
foreach ($configs as $id => $config) {
204+
$apiseries_client = ApiSeriesClient::getInstance($id);
205+
$series = $apiseries_client->search(Request::option('search_term'));
206+
207+
if (!empty($series)) {
208+
if (!$is_admin) {
209+
$filtered_series = [];
210+
foreach ($series as $series_id => $title) {
211+
if (in_array($series_id, $user_series)) {
212+
$filtered_series[$series_id] = $title;
213+
}
214+
}
215+
216+
$all_series[$id] = $filtered_series;
217+
} else {
218+
$all_series[$id] = $series;
219+
}
220+
}
221+
}
222+
223+
$this->render_json($all_series);
224+
}
194225
}

controllers/course.php

-22
Original file line numberDiff line numberDiff line change
@@ -341,28 +341,6 @@ public function config_action()
341341
$this->set_title($this->_('Opencast Konfiguration'));
342342
$this->response->add_header('X-Title', rawurlencode($this->_('Serie mit Veranstaltung verknüpfen')));
343343
$this->configs = OCConfig::getBaseServerConf();
344-
345-
$user_series = OCSeminarSeries::getSeriesByUserMemberStatus($GLOBALS['user']->id, 'dozent');
346-
347-
348-
$is_admin = $GLOBALS['perm']->have_studip_perm('admin', Context::getId());
349-
350-
foreach ($this->configs as $id => $config) {
351-
$apiseries_client = ApiSeriesClient::getInstance($id);
352-
if ($series = $apiseries_client->getAll()) {
353-
if (!$is_admin) {
354-
$filtered_series = [];
355-
foreach ($series as $series_index => $series_obj) {
356-
if (in_array($series_obj->identifier, $user_series)) {
357-
$filtered_series[] = $series_obj;
358-
}
359-
}
360-
$this->all_series[$id] = $filtered_series;
361-
} else {
362-
$this->all_series[$id] = $series;
363-
}
364-
}
365-
}
366344
}
367345

368346
public function edit_action($course_id)

views/course/config.php

+54-28
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<? use Studip\Button, Studip\LinkButton; ?>
22

3+
<?= MessageBox::info($_('Ihr Suchbegriff muss mindestens 3 Zeichen lang sein und es werden maximal 100 Treffer angezeigt.')) ?>
4+
35
<form action="<?= $controller->url_for('course/edit/' . $course_id) ?>"
46
method=post id="select-series" class="default"
57
data-unconnected="<?= (empty($connectedSeries) ? 1 : 'false'); ?>">
@@ -8,29 +10,28 @@
810
<?= $_('Serie mit Veranstaltung verknüpfen') ?>
911
</legend>
1012

11-
<? if (!empty($all_series)) : ?>
12-
<label>
13-
<select name="series"
14-
id="series-select"
15-
data-placeholder="<?= $_('Wählen Sie eine Series aus.') ?>"
16-
style="max-width: 700px"
17-
>
18-
19-
<? foreach ($configs as $id => $config): ?>
20-
<optgroup label="<?= $_(sprintf('%s. Opencast-System', $id)) ?>">
21-
<? foreach ($all_series[$id] as $serie) : ?>
22-
<option value='{"config_id":"<?= $id ?>", "series_id":"<?= $serie->identifier ?>"}'
23-
class="nested-item">
24-
<?= htmlReady($serie->title) ?>
25-
</option>
26-
<? endforeach; ?>
27-
</optgroup>
28-
<? endforeach ?>
29-
</select>
30-
</label>
31-
<? else: ?>
32-
<?= MessageBox::info($_('Es wurden in Opencast keine Serien gefunden.')) ?>
33-
<? endif; ?>
13+
<label>
14+
Suche
15+
<input type="text"
16+
id="search_term"
17+
placeholder="<?= $_('Serientitel oder Beschreibung') ?>"
18+
onKeyUp="runSearch()">
19+
</label>
20+
21+
<label>
22+
Gefunde Serien
23+
<select name="series"
24+
id="series-select"
25+
data-placeholder="<?= $_('Wählen Sie eine Series aus.') ?>"
26+
>
27+
28+
<? foreach ($configs as $id => $config): ?>
29+
<optgroup label="<?= $_(sprintf('%s. Opencast-System', $id)) ?>" id="oc_server_<?= $id ?>">
30+
</optgroup>
31+
<? endforeach ?>
32+
</select>
33+
</label>
34+
3435
</fieldset>
3536

3637

@@ -41,9 +42,34 @@ class="nested-item">
4142
</form>
4243

4344
<script type="text/javascript">
44-
jQuery("#series-select").select2({
45-
max_selected_options: 1,
46-
width: "700px",
47-
dropdownParent: $('#select-series')
48-
});
45+
function runSearch()
46+
{
47+
let search_term = $('#search_term').val();
48+
fetch(STUDIP.URLHelper.getURL('plugins.php/opencast/ajax/search_series/?search_term=' + search_term))
49+
.then((response) => response.json())
50+
.then((data) => {
51+
for (let config_id in data) {
52+
console.log(data[config_id], $('#oc_server_' + config_id));
53+
$('#oc_server_' + config_id).replaceOptions(data[config_id], config_id);
54+
}
55+
56+
// console.log(data);
57+
});
58+
}
59+
60+
(function($, window) {
61+
$.fn.replaceOptions = function(options, config_id) {
62+
var self, $option;
63+
64+
this.empty();
65+
self = this;
66+
67+
$.each(options, function(index, option) {
68+
$option = $("<option></option>")
69+
.attr("value", '{"config_id":"' + config_id + '", "series_id":"' + index + '"}')
70+
.text(option);
71+
self.append($option);
72+
});
73+
};
74+
})(jQuery, window);
4975
</script>

0 commit comments

Comments
 (0)