Skip to content

Commit

Permalink
Merge pull request #173 from ArtrenH/main
Browse files Browse the repository at this point in the history
Links in Additional Info + Fixes + Small Changes
  • Loading branch information
OfficialFreak authored Sep 25, 2023
2 parents 67d837a + be589cb commit 6659562
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 37 deletions.
17 changes: 8 additions & 9 deletions backend/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,22 @@ def get_plan_file(self,
"""Return the contents of a plan file from the cache."""
# self._logger.debug(f"get_plan_file({day!r}, {timestamp!r}, {filename!r})")

if newest_before:
if newest_before and not isinstance(timestamp, str):
timestamps = self.get_timestamps(day)
if not isinstance(timestamp, str):
timestamps = [t for t in timestamps if t <= timestamp]
timestamps = [t for t in timestamps if t <= timestamp]

for timestamp in timestamps:
for older_timestamp in timestamps:
try:
return self.get_plan_file(day, timestamp, filename, newest_before=False)
return self.get_plan_file(day, older_timestamp, filename, newest_before=False)
except OSError:
pass
else:
raise FileNotFoundError
else:
path = self.get_plan_path(day, timestamp) / filename

path = self.get_plan_path(day, timestamp) / filename

with open(path, "r", encoding="utf-8") as f:
return f.read()
with open(path, "r", encoding="utf-8") as f:
return f.read()

def store_meta_file(self, content: str, filename: str):
"""Store a meta file in the cache such as "meta.json"."""
Expand Down
3 changes: 0 additions & 3 deletions backend/meta_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ def iterate_daily_extractors(self) -> typing.Generator[DailyMetaExtractor, None,
try:
plan_kl = self.cache.get_plan_file(day, timestamp, "PlanKl.xml")
except FileNotFoundError:
self._logger.warning(
f"Timestamp {timestamp!s} for day {day!s} has no PlanKl.xml file."
)
continue

extractor = DailyMetaExtractor(plan_kl)
Expand Down
4 changes: 2 additions & 2 deletions backend/plan_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


class PlanProcessor:
VERSION = "74"
VERSION = "75"

def __init__(self, cache: Cache, school_number: str, *, logger: logging.Logger):
self._logger = logger
Expand Down Expand Up @@ -67,7 +67,7 @@ def compute_plans(self, date: datetime.date, timestamp: datetime.datetime):
self._logger.warning(f"=> Could not find Indiware form plan for date {date!s} and timestamp {timestamp!s}.")
else:
try:
vplan_kl = self.cache.get_plan_file(date, timestamp, "VPlanKl.xml", newest_before=True)
vplan_kl = self.cache.get_plan_file(date, timestamp, "VplanKl.xml", newest_before=True)
except FileNotFoundError:
vplan_kl = None
plan_extractor = PlanExtractor(plan_kl, vplan_kl, self.teachers.abbreviation_by_surname(),
Expand Down
7 changes: 5 additions & 2 deletions backend/vplan_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,16 @@ def periods_to_block_label(periods: list[int]) -> str:


def _parse_periods(period_str: str) -> list[int]:
def period_str_to_int(string: str) -> int:
return int(string.replace("Stunde", "").replace(".", ""))

if not period_str:
return []
elif "-" not in period_str:
return [int(period_str)]
return [period_str_to_int(period_str)]
else:
begin, end = period_str.split("-")
return list(range(int(begin), int(end) + 1))
return list(range(period_str_to_int(begin), period_str_to_int(end) + 1))


def parse_periods(period_str: str) -> list[int]:
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 4 additions & 8 deletions client/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
let api_base;
let selected_revision;
let meta;
let all_meta;
let enabled_dates;
let grouped_rooms;
let course_lists;
Expand All @@ -62,7 +61,6 @@
api_base = null;
selected_revision = ".newest";
meta = {};
all_meta = {};
enabled_dates = [];
grouped_rooms = [];
course_lists = {};
Expand All @@ -83,8 +81,7 @@
let data = localStorage.getItem(`${school_num}_meta`);
if (data !== "undefined" && data) {
data = JSON.parse(data);
all_meta = data;
meta = data.meta;
meta = data;
all_rooms = data.rooms;
teacher_list = Object.keys(data.teachers);
grouped_forms = data.forms.grouped_forms;
Expand All @@ -105,8 +102,7 @@
throw error;
}
}
all_meta = data;
meta = data.meta;
meta = data;
all_rooms = data.rooms;
teacher_list = Object.keys(data.teachers);
grouped_forms = data.forms.grouped_forms;
Expand Down Expand Up @@ -284,7 +280,7 @@
$: school_num && (api_base = `/api/v69.420/${school_num}`);
$: school_num && reset_plan_vars();
$: school_num && get_meta();
$: all_revisions = [".newest"].concat((all_meta?.dates || {})[date] || []);
$: all_revisions = [".newest"].concat((meta?.dates || {})[date] || []);
$: school_num && get_preferences();
$: all_rooms && (grouped_rooms = group_rooms(all_rooms));
$: $logged_in && get_settings();
Expand Down Expand Up @@ -386,7 +382,7 @@
</div>
</div>
{#if $current_page.substring(0, 4) === "plan"}
<Plan bind:api_base bind:school_num bind:date bind:plan_type bind:plan_value bind:all_rooms bind:all_meta bind:selected_revision bind:enabled_dates external_times={$settings.external_times} />
<Plan bind:api_base bind:school_num bind:date bind:plan_type bind:plan_value bind:all_rooms bind:meta bind:selected_revision bind:enabled_dates external_times={$settings.external_times} />
{:else}
<Weekplan bind:api_base bind:week_start={date} bind:plan_type bind:plan_value />
{/if}
Expand Down
158 changes: 147 additions & 11 deletions client/src/Plan.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
import { swipe } from 'svelte-gestures';
import {preferences, settings, title} from './stores.js';
import {arraysEqual, customFetch, format_date, navigate_page, should_date_be_cached} from "./utils.js";
import Dropdown from './Components/Dropdown.svelte';
export let api_base;
export let school_num;
export let date;
export let plan_type;
export let plan_value;
export let all_meta;
export let meta;
export let show_title = true;
export let extra_height = true;
export let week_letter = "";
Expand Down Expand Up @@ -57,10 +58,10 @@
return;
}
// Check the validity of the plan value
if((plan_type === "rooms" || plan_type === "teachers") && (!Object.keys(all_meta[plan_type]).includes(entity))) {
if((plan_type === "rooms" || plan_type === "teachers") && (!Object.keys(meta[plan_type]).includes(entity))) {
reset_plan_vars();
return;
} else if((plan_type === "forms") && !Object.keys(all_meta.forms.forms).includes(entity)) {
} else if((plan_type === "forms") && !Object.keys(meta.forms.forms).includes(entity)) {
reset_plan_vars();
return;
}
Expand Down Expand Up @@ -126,6 +127,7 @@
}
});
location.hash = gen_location_hash();
console.log(info);
}
function periods_to_block_label(periods) {
Expand Down Expand Up @@ -205,8 +207,8 @@
let full_teacher_name = null;
let teacher_contact_link = null;
$: if (plan_type === "teachers") {
full_teacher_name = all_meta.teachers[plan_value]?.surname || null;
teacher_contact_link = all_meta.teachers[plan_value]?.contact_link || null;
full_teacher_name = meta.teachers[plan_value]?.surname || null;
teacher_contact_link = meta.teachers[plan_value]?.contact_link || null;
}
let preferences_apply = true;
Expand Down Expand Up @@ -316,11 +318,43 @@
{#if info}
{#if info.additional_info.length > 0}
<div class="additional-info">
{#each info.additional_info as cur_info}
{#if cur_info !== null}
{cur_info}
{#each info.processed_additional_info as info_paragraph}
{#if info_paragraph.length > 0}
<div class="inline-wrapper">
{#each info_paragraph as text_segment}
{#if text_segment.link?.value.length === 1}
<button class="no-btn-visuals" on:click={() => {
date = text_segment.link.date;
plan_type = text_segment.link.type;
plan_value = text_segment.link.value[0];
}}>
<div class="clickable">{text_segment.text}</div>
</button>
{:else if text_segment.link?.value.length >= 2}
<div class="fit-content-width">
<Dropdown let:toggle small={true} transform_origin_x="50%">
<button slot="toggle_button" on:click={toggle} class="toggle-button">
<span class="grow">{text_segment.text}</span>
<span class="material-symbols-outlined dropdown-arrow">arrow_drop_down</span>
</button>
{#each text_segment.link.value as item}
<button on:click={() => {
date=text_segment.link.date;
plan_type = text_segment.link.type;
plan_value = item;
}}>{item}</button>
{/each}
</Dropdown>
</div>
{:else}
<button class="no-btn-visuals">{text_segment.text}</button>
{/if}
{/each}
</div>
{:else}
<div class="info-spacer"></div>
{/if}
<br>
{/each}
</div>
{/if}
Expand Down Expand Up @@ -352,6 +386,106 @@
</div>
<style lang="scss">
.inline-wrapper {
display: flex;
flex-direction: row;
flex-wrap: wrap;
row-gap: .1em;
}
.info-spacer {
height: 5px;
}
.dropdown-arrow {
font-size: 1.4em;
display: block;
transition: transform .2s ease;
pointer-events: none;
@media only screen and (min-width: 1501px) {
font-size: 1em;
margin-left: .2em;
&.centered_txt {
position: absolute;
right: 10px;
}
}
}
:global(.open) .dropdown-arrow {
transform: rotate(180deg);
}
.fit-content-width {
width: fit-content;
}
.fit-content-width .dropdown-wrapper button, .max-width .dropdown-wrapper button {
border: none;
background: transparent;
color: var(--text-color);
transition: background-color .2s ease;
width: 100%;
padding: 2px 0px 2px 5px;
font-size: inherit;
&:hover, &:focus-visible {
background-color: rgba(0, 0, 0, 0.5);
}
&.toggle-button {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
background: rgba(255, 255, 255, 0.08);
border-radius: 5px;
overflow: hidden;
text-align: left;
font-size: inherit;
font-weight: inherit;
color: var(--text-color);
span.grow {
flex: 1;
white-space: nowrap;
}
&.center-align {
text-align: center;
}
&:hover, &:focus-visible {
background-color: rgba(255, 255, 255, 0.15);
}
}
}
.no-btn-visuals {
border: 0;
background: none;
padding: 0;
margin: 0;
text-align: start;
font-size: inherit;
color: var(--text-color);
white-space: pre;
word-break: break-all;
}
.clickable {
background: rgba(255, 255, 255, 0.08);
border-radius: 5px;
padding: 2px 5px;
transition: background-color 0.2s ease;
&:hover, &:focus-visible {
background-color: rgba(255, 255, 255, 0.2);
}
}
.day-controls {
position: fixed;
bottom: 0;
Expand Down Expand Up @@ -484,16 +618,18 @@
.additional-info {
position: relative;
font-size: clamp(0.938rem, 3vmin, 1.875rem);
font-size: var(--font-size-base);
line-height: 1.5;
border: clamp(1px, .3vmax, 3px) solid rgba(255, 255, 255, 0.2);
padding: 10px;
padding-top: calc(1vmax + .5rem);
padding-top: calc(10px + var(--font-size-md) / 2);
padding-bottom: calc(5px + var(--font-size-md) / 2);
margin-top: 30px;
border-radius: 5px;
&::before {
content: "Informationen";
font-size: var(--font-size-md);
color: rgba(255, 255, 255, 0.2);
background: var(--background);
padding: 0px 5px;
Expand Down
2 changes: 1 addition & 1 deletion client/src/SchoolManager.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
function get_school_name_by_id(school_id) {
for (let school of schools) {
if (school.id === school_id.toString()) {
return school.name
return school.display_name
}
}
return ""
Expand Down
2 changes: 1 addition & 1 deletion var.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def validate_bool(elem):


def validate_color(elem):
if not re.search(r'^#(?:[0-9a-fA-F]{3}){1,2}$', elem):
if not re.fullmatch(r'^#(?:[0-9a-fA-F]{3}){1,2}$', elem):
return False
return True

Expand Down

0 comments on commit 6659562

Please sign in to comment.