Add default grid view for publications

master
Skylar Ittner 6 years ago
parent fe184571b5
commit a3fac92866

@ -88,5 +88,8 @@ define("STRINGS", [
"format" => "Format", "format" => "Format",
"addresses comma separated" => "Addresses (comma separated)", "addresses comma separated" => "Addresses (comma separated)",
"editor" => "Editor", "editor" => "Editor",
"publications" => "Publications" "publications" => "Publications",
"grid" => "Grid",
"list" => "List",
"search" => "Search"
]); ]);

@ -110,7 +110,7 @@ for ($i = 0; $i < count($pubs); $i++) {
$pubs[$i]["editbtn"] = '<a class="btn btn-primary btn-sm" href="app.php?page=content&pubid=' . $pubs[$i]['pubid'] . '"><i class="fas fa-edit"></i> ' . lang("edit", false) . '</a>'; $pubs[$i]["editbtn"] = '<a class="btn btn-primary btn-sm" href="app.php?page=content&pubid=' . $pubs[$i]['pubid'] . '"><i class="fas fa-edit"></i> ' . lang("edit", false) . '</a>';
$pubs[$i]["editbtn"] .= ' <a class="btn btn-secondary btn-sm" href="app.php?page=editpub&id=' . $pubs[$i]['pubid'] . '"><i class="fas fa-paint-brush"></i> ' . lang("format", false) . '</a>'; $pubs[$i]["editbtn"] .= ' <a class="btn btn-secondary btn-sm" href="app.php?page=editpub&id=' . $pubs[$i]['pubid'] . '"><i class="fas fa-paint-brush"></i> ' . lang("format", false) . '</a>';
} else { } else {
$pubs[$i]["editbtn"] = '<a class="btn btn-purple btn-sm" href="app.php?page=content&pubid=' . $pubs[$i]['pubid'] . '"><i class="fas fa-eye"></i> ' . lang("view", false) . '</a>'; $pubs[$i]["editbtn"] = '<a class="btn btn-info btn-sm" href="app.php?page=content&pubid=' . $pubs[$i]['pubid'] . '"><i class="fas fa-eye"></i> ' . lang("view", false) . '</a>';
} }
$pubs[$i]["clonebtn"] = '<a class="btn btn-success btn-sm" href="app.php?page=editpub&id=' . $pubs[$i]['pubid'] . '&clone=1"><i class="fas fa-clone"></i> ' . lang("clone", false) . '</a>'; $pubs[$i]["clonebtn"] = '<a class="btn btn-success btn-sm" href="app.php?page=editpub&id=' . $pubs[$i]['pubid'] . '&clone=1"><i class="fas fa-clone"></i> ' . lang("clone", false) . '</a>';
$pubs[$i]["pubdate"] = date(DATETIME_FORMAT, strtotime($pubs[$i]["pubdate"])); $pubs[$i]["pubdate"] = date(DATETIME_FORMAT, strtotime($pubs[$i]["pubdate"]));

@ -16,6 +16,7 @@ define("PAGES", [
"static/css/tables.css" "static/css/tables.css"
], ],
"scripts" => [ "scripts" => [
"static/js/shuffle.min.js",
"static/js/datatables.min.js", "static/js/datatables.min.js",
"static/js/home.js" "static/js/home.js"
], ],

@ -1,5 +1,4 @@
<?php <?php
/* This Source Code Form is subject to the terms of the Mozilla Public /* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@ -13,33 +12,169 @@ redirectifnotloggedin();
<div class="btn-group mb-4"> <div class="btn-group mb-4">
<a href="app.php?page=editpub" class="btn btn-success"><i class="fas fa-plus"></i> <?php lang("new publication"); ?></a> <a href="app.php?page=editpub" class="btn btn-success"><i class="fas fa-plus"></i> <?php lang("new publication"); ?></a>
</div> </div>
<table id="pubtable" class="table table-bordered table-hover table-sm">
<thead> <ul class="nav nav-tabs">
<tr> <li class="nav-item">
<th data-priority="0"></th> <a class="nav-link <?php echo $_GET['view'] != "list" ? "active" : "" ?>" href="./app.php?page=home&view=grid" role="tab"><i class="fas fa-th-large"></i> <?php lang("grid"); ?></a>
<th data-priority="1"><?php lang('actions'); ?></th> </li>
<th data-priority="1"><i class="fas fa-fw fa-font d-none d-md-inline"></i> <?php lang('name'); ?></th> <li class="nav-item">
<th data-priority="2"><i class="fas fa-fw fa-calendar d-none d-md-inline"></i> <?php lang('date'); ?></th> <a class="nav-link <?php echo $_GET['view'] == "list" ? "active" : "" ?>" href="./app.php?page=home&view=list" role="tab"><i class="fas fa-list-ul"></i> <?php lang("list"); ?></a>
<th data-priority="2"><i class="fas fa-fw fa-user d-none d-md-inline"></i> <?php lang('author'); ?></th> </li>
<th data-priority="4"><i class="fas fa-fw fa-star d-none d-md-inline"></i> <?php lang('theme'); ?></th> </ul>
<th data-priority="4"><i class="fas fa-fw fa-columns d-none d-md-inline"></i> <?php lang('columns'); ?></th>
<th data-priority="3"><i class="fas fa-fw fa-file d-none d-md-inline"></i> <?php lang('page size'); ?></th> <?php if ($_GET['view'] != "list") { ?>
<th data-priority="2"><i class="fas fa-fw fa-eye d-none d-md-inline"></i> <?php lang('visibility'); ?></th> <div class="row ml-1">
</tr> <div class="input-group">
</thead> <input type="text" id="search" placeholder="<?php lang("search"); ?>" class="form-control col-12 col-sm-6 col-md-4 col-lg-3" />
<tbody> </div>
</tbody> </div>
<tfoot> <div class="p-1"></div>
<tr> <div class="row" id="grid">
<th data-priority="0"></th> <div class="col-1 sizer-element"></div>
<th data-priority="1"><?php lang('actions'); ?></th> <?php
<th data-priority="1"><i class="fas fa-fw fa-font d-none d-md-inline"></i> <?php lang('name'); ?></th> $where = [];
<th data-priority="2"><i class="fas fa-fw fa-calendar d-none d-md-inline"></i> <?php lang('date'); ?></th> $where["OR #perms"] = [
<th data-priority="2"><i class="fas fa-fw fa-user d-none d-md-inline"></i> <?php lang('author'); ?></th> "uid" => $_SESSION['uid'],
<th data-priority="4"><i class="fas fa-fw fa-star d-none d-md-inline"></i> <?php lang('theme'); ?></th> "permname #logg" => "LOGGEDIN",
<th data-priority="4"><i class="fas fa-fw fa-columns d-none d-md-inline"></i> <?php lang('columns'); ?></th> "permname #link" => "LINK"
<th data-priority="3"><i class="fas fa-fw fa-file d-none d-md-inline"></i> <?php lang('page size'); ?></th> ];
<th data-priority="2"><i class="fas fa-fw fa-eye d-none d-md-inline"></i> <?php lang('visibility'); ?></th> $pubs = $database->select('publications', [
</tr> '[>]pub_permissions' => ['permid' => 'permid'],
</tfoot> '[>]page_sizes' => ['page_size' => 'sizeid']
</table> ], [
'pubid',
'pubname',
'uid',
'pubdate',
'style',
'columns',
'permname',
'pwd',
'publications.permid',
"page_size",
"sizename",
"landscape"
], $where);
$usercache = [];
foreach ($pubs as $p) {
if (is_null($p['uid'])) {
$p["username"] = "";
} else {
if (!isset($usercache[$p['uid']])) {
$usercache[$p['uid']] = getUserByID($p['uid']);
}
$p["username"] = $usercache[$p['uid']]['name'];
}
$p["pagesize"] = lang2("page size and orientation", [
"size" => $p["sizename"],
"orientation" => ( $p["landscape"] == 0 ? lang("portrait", false) : lang("landscape", false) )
], false);
$p["visibility"] = lang("visibility " . strtolower($p["permname"]), false);
$p['date'] = date(DATETIME_FORMAT, strtotime($p["pubdate"]));
$p['longdate'] = date("l F j Y", strtotime($p["pubdate"]));
if ($p["uid"] == $_SESSION['uid']) {
$p["editbtn"] = '<a class="btn btn-primary btn-sm" href="app.php?page=content&pubid=' . $p['pubid'] . '"><i class="fas fa-edit"></i> ' . lang("edit", false) . '</a>';
$p["editbtn"] .= ' <a class="btn btn-secondary btn-sm" href="app.php?page=editpub&id=' . $p['pubid'] . '"><i class="fas fa-paint-brush"></i> ' . lang("format", false) . '</a>';
} else {
$p["editbtn"] = '<a class="btn btn-info btn-sm" href="app.php?page=content&pubid=' . $p['pubid'] . '"><i class="fas fa-eye"></i> ' . lang("view", false) . '</a>';
}
$themedir = __DIR__ . "/../themes/";
$s = $p['style'];
$info = json_decode(file_get_contents($themedir . "$s/info.json"), TRUE);
$colorvars = json_decode(file_get_contents($themedir . "$s/vars.json"), TRUE);
?>
<div class="pub__brick col-12 col-sm-6 col-md-4 col-lg-3 mb-4" data-groups="[]" data-keywords="<?php echo htmlspecialchars($p['pubname']) . " " . $p['sizename'] . " " . $p['style'] . " " . $p['longdate']; ?>">
<style nonce="<?php echo $SECURE_NONCE; ?>">
#pub_card_<?php echo $p['pubid']; ?> {
background: <?php echo $colorvars['background']; ?>;
color: <?php echo $colorvars['text']; ?>;
border-color: <?php echo $colorvars['primary']; ?>;
border-width: 1px;
<?php
if (file_exists($themedir . "$s/background.png")) {
echo "background-image: url(themes/$s/background.png);";
} else if (file_exists($themedir . "$s/background.jpg")) {
echo "background-image: url(themes/$s/background.jpg);";
}
?>
}
#pub_card_<?php echo $p['pubid']; ?> .card-header {
color: <?php echo $colorvars['headings']; ?>;
}
#pub_card_<?php echo $p['pubid']; ?> .list-group-item {
background: <?php echo $colorvars['background']; ?>;
color: <?php echo $colorvars['text']; ?>;
border-color: <?php echo $colorvars['secondary']; ?>;
}
</style>
<div class="card mt-1" id="pub_card_<?php echo $p['pubid']; ?>">
<h5 class="card-header">
<?php echo htmlspecialchars($p['pubname']); ?>
</h5>
<div class="card-body">
<ul class="list-group">
<li class="list-group-item">
<i class="fas fa-fw fa-user"></i> <?php echo $p["username"]; ?>
</li>
<li class="list-group-item">
<i class="fas fa-fw fa-calendar"></i> <?php echo $p['date']; ?>
</li>
<li class="list-group-item">
<i class="fas fa-fw fa-file"></i> <?php echo $p["pagesize"]; ?>
</li>
<li class="list-group-item">
<i class="fas fa-fw fa-eye"></i> <?php echo $p["visibility"]; ?>
</li>
</ul>
</div>
<div class="card-footer">
<?php echo $p['editbtn']; ?>
</div>
</div>
</div>
<?php
}
?>
</div>
<?php } ?>
<?php if ($_GET['view'] == "list") { ?>
<table id="pubtable" class="table table-bordered table-hover table-sm">
<thead>
<tr>
<th data-priority="0"></th>
<th data-priority="1"><?php lang('actions'); ?></th>
<th data-priority="1"><i class="fas fa-fw fa-font d-none d-md-inline"></i> <?php lang('name'); ?></th>
<th data-priority="2"><i class="fas fa-fw fa-calendar d-none d-md-inline"></i> <?php lang('date'); ?></th>
<th data-priority="2"><i class="fas fa-fw fa-user d-none d-md-inline"></i> <?php lang('author'); ?></th>
<th data-priority="4"><i class="fas fa-fw fa-star d-none d-md-inline"></i> <?php lang('theme'); ?></th>
<th data-priority="4"><i class="fas fa-fw fa-columns d-none d-md-inline"></i> <?php lang('columns'); ?></th>
<th data-priority="3"><i class="fas fa-fw fa-file d-none d-md-inline"></i> <?php lang('page size'); ?></th>
<th data-priority="2"><i class="fas fa-fw fa-eye d-none d-md-inline"></i> <?php lang('visibility'); ?></th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<th data-priority="0"></th>
<th data-priority="1"><?php lang('actions'); ?></th>
<th data-priority="1"><i class="fas fa-fw fa-font d-none d-md-inline"></i> <?php lang('name'); ?></th>
<th data-priority="2"><i class="fas fa-fw fa-calendar d-none d-md-inline"></i> <?php lang('date'); ?></th>
<th data-priority="2"><i class="fas fa-fw fa-user d-none d-md-inline"></i> <?php lang('author'); ?></th>
<th data-priority="4"><i class="fas fa-fw fa-star d-none d-md-inline"></i> <?php lang('theme'); ?></th>
<th data-priority="4"><i class="fas fa-fw fa-columns d-none d-md-inline"></i> <?php lang('columns'); ?></th>
<th data-priority="3"><i class="fas fa-fw fa-file d-none d-md-inline"></i> <?php lang('page size'); ?></th>
<th data-priority="2"><i class="fas fa-fw fa-eye d-none d-md-inline"></i> <?php lang('visibility'); ?></th>
</tr>
</tfoot>
</table>
<?php } ?>

@ -1,56 +1,70 @@
var pubtable = $('#pubtable').DataTable({ if ($("#grid").length) {
responsive: { window.shuffleInstance = new window.Shuffle(document.getElementById('grid'), {
details: { itemSelector: '.pub__brick',
display: $.fn.dataTable.Responsive.display.modal({ sizer: '.sizer-element',
header: function (row) { });
var data = row.data();
return "<i class=\"fa fa-cube fa-fw\"></i> " + data[2]; $("#search").on("keyup", function () {
} var q = $("#search").val().toLowerCase();
}), shuffleInstance.filter(function (element) {
renderer: $.fn.dataTable.Responsive.renderer.tableAll({ return element.getAttribute('data-keywords').toLowerCase().includes(q);
tableClass: 'table' });
}), });
type: "column" } else {
} var pubtable = $('#pubtable').DataTable({
}, responsive: {
columnDefs: [ details: {
{ display: $.fn.dataTable.Responsive.display.modal({
targets: 0, header: function (row) {
className: 'control', var data = row.data();
orderable: false return "<i class=\"fa fa-cube fa-fw\"></i> " + data[2];
}, }
{ }),
targets: 1, renderer: $.fn.dataTable.Responsive.renderer.tableAll({
orderable: false tableClass: 'table'
}),
type: "column"
}
}, },
{ columnDefs: [
targets: 4, {
orderable: false targets: 0,
} className: 'control',
], orderable: false
order: [ },
[2, 'asc'] {
], targets: 1,
serverSide: true, orderable: false
ajax: { },
url: "lib/getpubtable.php", {
dataFilter: function (data) { targets: 4,
var json = jQuery.parseJSON(data); orderable: false
json.data = []; }
json.pubs.forEach(function (row) { ],
json.data.push([ order: [
"", [2, 'asc']
row.editbtn + " " + row.clonebtn, ],
row.pubname, serverSide: true,
row.pubdate, ajax: {
row.username, url: "lib/getpubtable.php",
row.style, dataFilter: function (data) {
row.columns, var json = jQuery.parseJSON(data);
row.pagesize, json.data = [];
row.visibility json.pubs.forEach(function (row) {
]); json.data.push([
}); "",
return JSON.stringify(json); row.editbtn + " " + row.clonebtn,
row.pubname,
row.pubdate,
row.username,
row.style,
row.columns,
row.pagesize,
row.visibility
]);
});
return JSON.stringify(json);
}
} }
} });
}); }

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save