-
Notifications
You must be signed in to change notification settings - Fork 2
/
filters.php
103 lines (82 loc) · 2.4 KB
/
filters.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
require 'inc.bootstrap.php';
do_logincheck();
if ( isset($_POST['index_filter'], $_POST['index_query'], $_POST['index_project']) ) {
$user->update(array(
'index_filter' => trim($_POST['index_filter']),
'index_query' => trim($_POST['index_query']),
'index_project' => trim($_POST['index_project']),
));
return do_redirect('index');
}
else if ( isset($_POST['id'], $_POST['name'], $_POST['jql']) ) {
$id = $_POST['id'];
$name = $_POST['name'];
$jql = $_POST['jql'];
if ( !$jql || ( !$id && !$name ) ) {
exit('Missing input');
}
// Update
if ( $id ) {
$update = array(
'jql' => trim($jql),
);
$name and $update += compact('name');
$response = jira_put('filter/' . $id, $update, $error, $info);
}
// Insert
else {
$response = jira_post('filter', array(
'name' => trim($name),
'jql' => trim($jql),
'favourite' => 1,
), $error, $info);
}
if ( !$error ) {
return do_redirect('filters');
}
echo '<p>error: ' . (int)$error . '</p>';
echo '<p><a href="issue.php?key=' . $key . '">Back</a></p>';
echo '<pre>';
print_r($response);
print_r($info);
echo '</pre>';
exit;
}
$user->unsync();
$_title = 'Filters';
include 'tpl.header.php';
echo '<h1>Your filters</h1>';
?>
<form autocomplete="off" action method="post">
<p>Used if present, in order:</p>
<p>1. Index filter: <select name="index_filter"><option>-- None<?= html_options($user->filter_options, $user->index_filter) ?></select></p>
<p>2. Index query: <input name="index_query" value="<?= html($user->index_query) ?>" /></p>
<p>3. Index project: <input name="index_project" value="<?= html($user->index_project) ?>" /></p>
<p><button>Save</button></p>
</form>
<h2>Add / edit filter</h2>
<form autocomplete="off" action method="post">
<p>Filter: <select name="id"><option value="">-- NEW</option><?= html_options($user->filter_options) ?></select></p>
<p>Name: <input name="name" /></p>
<p>Query: <input name="jql" /></p>
<p><button>Save</button></p>
</form>
<script>
(function() {
var filters = <?= json_encode($user->filter_options_jql) ?>,
$select = $('select[name="id"]', 1),
$textfield = $('input[name="jql"]', 1);
$select.on('change', function(e) {
$textfield.value = filters[this.value] || '';
});
})();
</script>
<?php
echo '<pre>';
print_r($user->filters);
print_r($user->filter_options);
print_r($user->filter_options_jql);
print_r($user->filter_query_options);
echo '</pre>';
include 'tpl.footer.php';