3 require_once('../include/admin-header.php');
4 require_once('../include/test-name-resolver.php');
6 if ($action == 'dashboard') {
7 if (array_key_exists('metric_id', $_POST)) {
8 $metric_id = intval($_POST['metric_id']);
11 if (!$db->query_and_get_affected_rows("UPDATE test_configurations SET config_is_in_dashboard = false WHERE config_metric = $1", array($metric_id))) {
13 notice("Failed to remove some configurations from the dashboard.");
16 else if (array_key_exists('metric_platforms', $_POST)) {
17 foreach ($_POST['metric_platforms'] as $platform_id) {
18 if (!$db->query_and_get_affected_rows("UPDATE test_configurations SET config_is_in_dashboard = true
19 WHERE config_metric = $1 AND config_platform = $2", array($metric_id, $platform_id))) {
21 notice("Failed to add configurations for metric $metric_id and platform $platform_id to the dashboard.");
27 notice("Updated the dashboard.");
28 regenerate_manifest();
31 notice('Invalid parameters');
32 } else if ($action == 'update') {
33 if (!update_field('tests', 'test', 'url'))
34 notice('Invalid parameters');
35 } else if ($action == 'add') {
36 if (array_key_exists('test_id', $_POST) && array_key_exists('metric_name', $_POST)) {
37 $id = intval($_POST['test_id']);
38 $aggregator = intval($_POST['metric_aggregator']);
40 notice('Invalid aggregator. You must specify one.');
42 $metric_id = $db->insert_row('test_metrics', 'metric',
43 array('test' => $id, 'name' => $_POST['metric_name'], 'aggregator' => $aggregator));
45 notice("Could not insert the new metric for test $id");
47 add_job('aggregate', '{"metricIds": [ ' . $metric_id . ']}');
48 notice("Inserted the metric for test $id");
51 } else if (array_key_exists('metric_id', $_POST))
52 regenerate_manifest();
54 notice('Invalid parameters');
58 $aggregators = array();
59 if ($aggregators_table = $db->fetch_table('aggregators')) {
60 foreach ($aggregators_table as $aggregator_row)
61 $aggregators[$aggregator_row['aggregator_id']] = $aggregator_row['aggregator_name'];
64 $test_name_resolver = new TestNameResolver($db);
65 if ($test_name_resolver->tests()) {
66 $name_to_platform = array();
68 foreach ($db->fetch_table('platforms') as $platform)
69 $name_to_platform[$platform['platform_name']] = $platform;
71 $platform_names = array_keys($name_to_platform);
72 asort($platform_names);
75 $selected_parent_full_name = trim(array_get($_SERVER, 'PATH_INFO', ''), '/');
76 $selected_parent = $test_name_resolver->test_id_for_full_name($selected_parent_full_name);
78 echo '<h2>' . htmlspecialchars($selected_parent_full_name) . '</h2>';
83 <tr><td>Test ID</td><td>Full Name</td><td>Parent ID</td><td>URL</td>
84 <td>Metric ID</td><td>Metric Name</td><td>Aggregator</td><td>Dashboard</td>
89 foreach ($test_name_resolver->tests() as $test) {
90 if ($test['test_parent'] != $selected_parent['test_id'])
93 $test_id = $test['test_id'];
94 $test_metrics = $test_name_resolver->metrics_for_test_id($test_id);
95 $row_count = count($test_metrics);
96 $child_metrics = $test_name_resolver->child_metrics_for_test_id($test_id);
97 $linked_test_name = htmlspecialchars($test['full_name']);
100 $linked_test_name = '<a href="/admin/tests/' . htmlspecialchars($test['full_name']) . '">' . $linked_test_name . '</a>';
103 $tbody_class = $odd ? 'odd' : 'even';
106 $test_url = htmlspecialchars($test['test_url']);
109 <tbody class="$tbody_class">
111 <td rowspan="$row_count">$test_id</td>
112 <td rowspan="$row_count">$linked_test_name</td>
113 <td rowspan="$row_count">{$test['test_parent']}</td>
114 <td rowspan="$row_count">
115 <form method="POST"><input type="hidden" name="id" value="$test_id">
116 <input type="hidden" name="action" value="update">
117 <input type="url" name="url" value="$test_url" size="80"></form></td>
122 foreach ($test_metrics as $metric) {
123 $aggregator_name = array_get($aggregators, $metric['metric_aggregator'], '');
124 if ($aggregator_name) {
125 $aggregator_action = '<form method="POST"><input type="hidden" name="metric_id" value="'. $metric['metric_id']
126 . '"><button type="submit" name="action" value="add">Regenerate</button></form>';
128 $aggregator_action = '';
137 $metric_id = $metric['metric_id'];
139 <td><a href="/admin/test-configurations?metric=$metric_id">$metric_id</a></td>
140 <td>{$metric['metric_name']}</td>
141 <td>$aggregator_name $aggregator_action</td>
142 <td><form method="POST"><input type="hidden" name="metric_id" value="$metric_id">
145 foreach ($platform_names as $platform_name) {
146 $platform_name = htmlspecialchars($platform_name);
147 $platform = $name_to_platform[$platform_name];
148 $configurations = $test_name_resolver->configurations_for_metric_and_platform($metric_id, $platform['platform_id']);
149 if (!$configurations)
151 echo "<label><input type=\"checkbox\" name=\"metric_platforms[]\" value=\"{$platform['platform_id']}\"";
152 if ($db->is_true($configurations[0]['config_is_in_dashboard']))
154 else if ($db->is_true($platform['platform_hidden']))
156 echo ">$platform_name</label>";
160 <button type="submit" name="action" value="dashboard">Save</button></form>
167 if ($child_metrics) {
169 <td colspan="5"><form method="POST">
170 <input type="hidden" name="test_id" value="$test_id">
171 <label>Name<select name="metric_name">
174 foreach ($child_metrics as $metric_name) {
175 $metric_name = htmlspecialchars($metric_name);
177 <option>$metric_name</option>";
183 <select name="metric_aggregator">
184 <option value="">-</option>
186 foreach ($aggregators as $id => $name) {
187 $name = htmlspecialchars($name);
189 <option value=\"$id\">$name</option>";
193 <button type="submit" name="action" value="add">Add</button></form></td>
211 include('../include/admin-footer.php');