sorted table

master
km0 2 years ago
parent 10e7400b5b
commit 36ed49425f

@ -4,20 +4,40 @@ export default {
const pads = ref([]);
const currentSort = ref("date");
const currentSortDir = ref("asc");
const sortedPads = computed(() => {
return pads.value.sort((a, b) => {
let modifier = 1;
if (currentSortDir.value === "desc") modifier = -1;
if (a[currentSort.value] < b[currentSort.value]) return -1 * modifier;
if (a[currentSort.value] > b[currentSort.value]) return 1 * modifier;
return 0;
});
});
const sort = function (s) {
if (s == currentSort.value) {
currentSortDir.value = currentSortDir.value === "asc" ? "desc" : "asc";
}
currentSort.value = s;
};
const columns = ["title", "overview", "categories", "date"];
fetch("http://localhost:3146/")
.then((res) => res.json())
.then((data) => (pads.value = data));
return { pads, columns };
return { pads, columns, sortedPads, sort };
},
template: `
<table>
<tr class="header">
<th v-for="column in columns">{{column }}</th>
<th v-for="column in columns" @click='sort(column)'>{{column }}</th>
</tr>
<tr v-for="(pad, index) in pads" key="pad.title, index" :class="pad.category">
<tr v-for="(pad, index) in sortedPads" key="pad.title, index" :class="pad.category">
<td class="title">

@ -1,6 +1,8 @@
import logging
logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)
from datetime import datetime
# Flask application to serve the web pages
from flask import Flask, request, redirect, url_for, jsonify
@ -48,7 +50,6 @@ class PrefixMiddleware(object):
# create flask application
app = Flask(__name__)
CORS(app)
# MakoTemplates(app)
# Url prefix for the soupboat
@ -74,7 +75,7 @@ def add_pad(link, title, overview, categories, date):
text = page.text()
new_row = f'|-\n| {link} || {title} || {overview} || {categories} || {date}\n|-\n' + '|}'
new_row = f'|-\n| {link} || {title} || {overview} || {categories} || {date} \n|-\n' + '|}'
text = text.replace('|}', new_row)
@ -84,10 +85,10 @@ def add_pad(link, title, overview, categories, date):
def get_pads():
site = mwclient.Site('pzwiki.wdka.nl', path='/mw-mediadesign/')
site.login(
username=os.environ.get('MW_BOT'),
password=os.environ.get('MW_KEY')
password=os.environ.get('MW_KEY'),
)
html = site.api('parse', prop='text', page=padliography)
@ -95,7 +96,7 @@ def get_pads():
headers = [header.text.lower().strip() for header in table.find_all('th')]
pads = [
{headers[i]: cell.text for i, cell in enumerate(row.find_all('td'))}
{headers[i]: cell.text.rstrip('\n') for i, cell in enumerate(row.find_all('td'))}
for row in table.find_all('tr')]
pads = [ pad for pad in pads if pad != {}]
return pads
@ -119,6 +120,8 @@ def home():
categories = request.json.get('categories', '')
date = request.json.get('date', None)
date = datetime.strftime(datetime.strptime(date, 'yyyy-mm-dd'), 'dd-mm-yyyy')
add_pad(link, title, overview, categories, date)
redirect(url_for('home'))

@ -4,6 +4,7 @@ charset-normalizer==2.0.12
click==8.1.3
colorama==0.4.4
Flask==2.1.2
Flask-Cors==3.0.10
Flask-Mako==0.4
idna==3.3
importlib-metadata==4.11.4

Loading…
Cancel
Save