Search overhaul possibly finished?

This commit is contained in:
Erik Thuning 2022-03-03 11:37:35 +01:00
parent 0f66c8212f
commit 3fae0ce1ff
5 changed files with 63 additions and 36 deletions

@ -85,7 +85,7 @@
</th> </th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody class="¤type¤">
¤rows¤ ¤rows¤
</tbody> </tbody>
</table> </table>
@ -110,20 +110,19 @@
<td class="status ¤status¤"> <td class="status ¤status¤">
</td> </td>
<td colspan="3"> <td colspan="3">
<div class="minitable"> <dl>
¤details¤ ¤details¤
</div> </dl>
</td> </td>
</tr> </tr>
¤¤ product_detail ¤¤ ¤¤ product_detail ¤¤
<span class="minitable_name"> <dt>
¤name¤ ¤name¤:
</span> </dt>
<span class="minitable_value"> <dd>
¤value¤ ¤value¤
</span> </dd>
<br/>
¤¤ template_management ¤¤ ¤¤ template_management ¤¤
<div> <div>

@ -128,6 +128,16 @@ abstract class Page extends Responder {
$this->fragments['user_table']); $this->fragments['user_table']);
} }
final protected function build_product_table($products) {
$rows = '';
foreach($products as $product) {
$rows .= $this->build_product_row($product);
}
return replace(array('rows' => $rows,
'type' => 'single'),
$this->fragments['product_table']);
}
final protected function build_product_row($product, $matches = null) { final protected function build_product_row($product, $matches = null) {
$prodlink = replace(array('id' => $product->get_id(), $prodlink = replace(array('id' => $product->get_id(),
'name' => $product->get_name(), 'name' => $product->get_name(),
@ -183,22 +193,13 @@ abstract class Page extends Responder {
if(is_array($value)) { if(is_array($value)) {
$value = implode(', ', $value); $value = implode(', ', $value);
} }
$out .= replace(array('name' => ucfirst($name), $out .= replace(array('name' => $product->get_label($name),
'value' => $value), 'value' => $value),
$this->fragments['product_detail']); $this->fragments['product_detail']);
} }
return $out; return $out;
} }
final protected function build_product_table($products) {
$rows = '';
foreach($products as $product) {
$rows .= $this->build_product_row($product);
}
return replace(array('rows' => $rows),
$this->fragments['product_table']);
}
final protected function build_user_loan_table($loans) { final protected function build_user_loan_table($loans) {
$rows = ''; $rows = '';
foreach($loans as $loan) { foreach($loans as $loan) {
@ -284,7 +285,8 @@ abstract class Page extends Responder {
'note' => $note), 'note' => $note),
$this->fragments['product_row']); $this->fragments['product_row']);
} }
return replace(array('rows' => $rows), return replace(array('rows' => $rows,
'type' => 'single'),
$this->fragments['product_table']); $this->fragments['product_table']);
} }

@ -228,6 +228,29 @@ class Product extends Entity {
return $matches; return $matches;
} }
public function get_label($name) {
switch($name) {
case 'brand':
return 'Tillverkare';
break;
case 'name':
return 'Namn';
break;
case 'invoice':
return 'Fakturanummer';
break;
case 'serial':
return 'Serienummer';
break;
case 'tags':
return 'Taggar';
break;
default:
return ucfirst($name);
break;
}
}
public function get_id() { public function get_id() {
return $this->id; return $this->id;
} }

@ -115,7 +115,7 @@ class SearchPage extends Page {
$value = substr($value, 1); $value = substr($value, 1);
} }
// Collect the new SearchTerm // Collect the new SearchTerm
$translated[] = new SearchTerm($key, $value, $flag); $translated[] = new SearchTerm($newkey, $value, $flag);
} }
} }
return $translated; return $translated;
@ -188,7 +188,8 @@ class SearchPage extends Page {
foreach($this->product_hits as $hit) { foreach($this->product_hits as $hit) {
$products .= $this->build_product_row($hit[0], $hit[1]); $products .= $this->build_product_row($hit[0], $hit[1]);
} }
$prod_table = replace(array('rows' => $products), $prod_table = replace(array('rows' => $products,
'type' => 'double'),
$this->fragments['product_table']); $this->fragments['product_table']);
} }
$user_table = 'Inga användare hittade.'; $user_table = 'Inga användare hittade.';

@ -104,10 +104,25 @@ tbody tr {
background-color: #d7e0eb; background-color: #d7e0eb;
} }
tbody tr:nth-child(odd) { tbody.single tr:nth-child(odd) {
background-color: #ebf0f5; background-color: #ebf0f5;
} }
tbody.double tr:is(:nth-child(4n+1), :nth-child(4n+2)) {
background-color: #ebf0f5;
}
tbody dl {
margin: 0;
display: grid;
grid-template-columns: 2fr 5fr;
}
tbody dd {
margin: 0;
grid-column: 2;
}
thead th, tfoot tr { thead th, tfoot tr {
background-color: #c3d1e2; background-color: #c3d1e2;
} }
@ -117,19 +132,6 @@ thead th:nth-last-child(-n+2) {
word-break: break-word; word-break: break-word;
} }
.minitable {
display: grid;
grid-template-columns: [col] auto [col] auto [col] auto [col];
}
.minitable_name {
grid-column: col 1;
}
.minitable_value {
grid-column: col 2;
}
input:disabled, textarea:disabled { input:disabled, textarea:disabled {
background-color: #ededed; background-color: #ededed;
} }