Skip to content

Commit

Permalink
Convert footer.mako to a Vue component
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkykh committed Jul 5, 2018
1 parent 2ed76da commit 29e4ce5
Show file tree
Hide file tree
Showing 14 changed files with 494 additions and 251 deletions.
17 changes: 15 additions & 2 deletions themes-default/slim/static/js/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,21 @@ const store = new Puex({
notifications: {
enabled: true
},
qualities: {},
statuses: {},
qualities: {
values: {},
anySets: {},
presets: {},
strings: {
values: {},
anySets: {},
presets: {},
cssClass: {}
}
},
statuses: {
values: {},
strings: {}
},
// Main config
config: {
wikiUrl: null,
Expand Down
22 changes: 21 additions & 1 deletion themes-default/slim/views/layouts/main.mako
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,25 @@
<%block name="content" />
</div>
</div><!-- /content -->
<%include file="/partials/footer.mako" />
<app-footer></app-footer>

<div class="scroll-wrapper top">
<span class="scroll-top-inner">
<i class="glyphicon glyphicon-circle-arrow-up"></i>
</span>
</div>

<div class="scroll-wrapper left">
<span class="scroll-left-inner">
<i id="scroll-left" class="glyphicon glyphicon-circle-arrow-left"></i>
</span>
</div>

<div class="scroll-wrapper right">
<span class="scroll-right-inner">
<i id="scroll-right" class="glyphicon glyphicon-circle-arrow-right"></i>
</span>
</div>
</div>
<script type="text/javascript" src="js/vender${('.min', '')[app.DEVELOPER]}.js?${sbPID}"></script>
<script type="text/javascript" src="js/lib/bootstrap-formhelpers.min.js?${sbPID}"></script>
Expand Down Expand Up @@ -125,9 +143,11 @@
<script src="js/lib/vue-native-websocket-2.0.7.js"></script>
<script src="js/notifications.js"></script>
<script src="js/store.js"></script>

<script>
Vue.component('app-link', httpVueLoader('js/templates/app-link.vue'));
</script>
<%include file="/vue-components/app-footer.mako"/>
<%include file="/vue-components/asset.mako"/>
<%include file="/vue-components/file-browser.mako"/>
<%include file="/vue-components/plot-info.mako"/>
Expand Down
80 changes: 0 additions & 80 deletions themes-default/slim/views/partials/footer.mako

This file was deleted.

128 changes: 128 additions & 0 deletions themes-default/slim/views/vue-components/app-footer.mako
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<script type="text/x-template" id="app-footer-template">
<!-- BEGIN FOOTER -->
<footer v-if="loggedIn">
<div class="footer clearfix">
<span class="footerhighlight">{{ stats.shows.total }}</span> Shows (<span class="footerhighlight">{{ stats.shows.active }}</span> Active)
| <span class="footerhighlight">{{ stats.episodes.downloaded }}</span><!-- Comment is needed to fix whitespace issues
--><template v-if="stats.episodes.snatched">
<span class="footerhighlight"><app-link :href="'manage/episodeStatuses?whichStatus=' + statuses.values.snatched" title="View overview of snatched episodes">+{{ stats.episodes.snatched }}</app-link></span>
Snatched
</template>
/ <span class="footerhighlight">{{ stats.episodes.total }}</span> Episodes Downloaded <span v-if="episodePercentage" class="footerhighlight">({{ episodePercentage }})</span>
| Daily Search: <span class="footerhighlight">{{ timeLeft.daily }}</span>
| Backlog Search: <span class="footerhighlight">{{ timeLeft.backlog }}</span>
<div>
<template v-if="memoryUsage">
Memory used: <span class="footerhighlight">{{ memoryUsage }}</span> |
</template>
Load time: <span class="footerhighlight">{{ loadTime }}s</span> / Mako: <span class="footerhighlight">{{ makoTime }}s</span> |
Branch: <span class="footerhighlight">{{ config.branch }}</span> |
Now: <span class="footerhighlight">{{ nowInUserPreset }}</span>
</div>
</div>
</footer>
<!-- END FOOTER -->
</script>
<%!
import json
from time import time
from medusa.app import backlog_search_scheduler, daily_search_scheduler
from medusa.helper.common import pretty_file_size
from medusa.show.show import Show
mem_usage = None
try:
from psutil import Process
from os import getpid
mem_usage = 'psutil'
except ImportError:
try:
import resource # resource module is unix only
mem_usage = 'resource'
except ImportError:
pass
%>
<script>
Vue.component('app-footer', {
template: '#app-footer-template',
data() {
<%
stats = Show.overall_stats()
timeleft_daily = str(daily_search_scheduler.timeLeft()).split('.')[0]
timeleft_backlog = str(backlog_search_scheduler.timeLeft()).split('.')[0]
loadtime = '%.4f' % (time() - sbStartTime)
makotime = '%.4f' % (time() - makoStartTime)
if not mem_usage:
memory = ''
elif mem_usage == 'resource':
memory = pretty_file_size(resource.getrusage(resource.RUSAGE_SELF).ru_maxrss)
elif mem_usage == 'psutil':
memory = pretty_file_size(Process(getpid()).memory_info().rss)
%>
return {
// Python conversions
loggedIn: ${json.dumps(loggedIn)},
stats: ${json.dumps(stats)},
timeLeft: {
daily: ${json.dumps(timeleft_daily)},
backlog: ${json.dumps(timeleft_backlog)},
},
loadTime: ${json.dumps(loadtime)},
makoTime: ${json.dumps(makotime)},
memoryUsage: ${json.dumps(memory)},
};
},
computed: Object.assign(store.mapState(['statuses']), {
episodePercentage() {
const { stats } = this;
const { episodes } = stats;
const { total, downloaded } = episodes;
if (total === 0) return '';
const [ integer, fractional ] = String((downloaded / total) * 100).split('.');
return integer + '.' + fractional.slice(0, 1) + '%';
},
nowInUserPreset() {
const { config, formatDateUsingPythonPreset } = this;
const { datePreset, timePreset } = config;
return formatDateUsingPythonPreset(new Date(), datePreset + ' ' + timePreset);
},
}),
methods: {
formatDateUsingPythonPreset(date, preset) {
const presetConversion = {
'%a': 'ddd', // Weekday name, short
'%A': 'dddd', // Weekday name, full
'%w': 'd', // Weekday number
'%d': 'DD', // Day of the month, zero-padded
'%b': 'MMM', // Month name, short
'%B': 'MMMM', // Month name, short
'%m': 'MM', // Day of the month, zero-padded
'%y': 'YY', // Year without century, zero-padded
'%Y': 'YYYY', // Year with century
'%H': 'HH', // Hour (24-hour clock), zero-padded
'%I': 'hh', // Hour (12-hour clock), zero-padded
'%p': 'A', // AM / PM
'%M': 'mm', // Minute, zero-padded
'%S': 'ss', // Second, zero-padded
'%f': '', // [UNSUPPORTED] Microsecond, zero-padded
'%z': 'ZZ', // UTC offset in the form +HHMM or -HHMM
'%Z': '', // [UNSUPPORTED] Time zone name
'%j': 'DDDD', // Day of the year, zero-padded
'%U': '', // [UNSUPPORTED] Week number of the year (Sunday as the first day of the week), zero padded
'%W': 'W', // Week number of the year (Monday as the first day of the week)
'%c': date.toLocaleString(), // [APPROXIMATE] Locale's appropriate date and time representation
'%x': date.toLocaleDateString(), // [APPROXIMATE] Locale's appropriate date representation
'%X': date.toLocaleTimeString(), // [APPROXIMATE] Locale's appropriate time representation
'%%': '%' // Literal '%' character
};
let newPreset = preset;
for (key in presetConversion) {
newPreset = newPreset.replace(key, presetConversion[key]);
}
return dateFns.format(date, newPreset);
}
}
});
</script>
17 changes: 15 additions & 2 deletions themes/dark/assets/js/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,21 @@ const store = new Puex({
notifications: {
enabled: true
},
qualities: {},
statuses: {},
qualities: {
values: {},
anySets: {},
presets: {},
strings: {
values: {},
anySets: {},
presets: {},
cssClass: {}
}
},
statuses: {
values: {},
strings: {}
},
// Main config
config: {
wikiUrl: null,
Expand Down
2 changes: 1 addition & 1 deletion themes/dark/assets/js/store.js.map

Large diffs are not rendered by default.

22 changes: 21 additions & 1 deletion themes/dark/templates/layouts/main.mako
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,25 @@
<%block name="content" />
</div>
</div><!-- /content -->
<%include file="/partials/footer.mako" />
<app-footer></app-footer>

<div class="scroll-wrapper top">
<span class="scroll-top-inner">
<i class="glyphicon glyphicon-circle-arrow-up"></i>
</span>
</div>

<div class="scroll-wrapper left">
<span class="scroll-left-inner">
<i id="scroll-left" class="glyphicon glyphicon-circle-arrow-left"></i>
</span>
</div>

<div class="scroll-wrapper right">
<span class="scroll-right-inner">
<i id="scroll-right" class="glyphicon glyphicon-circle-arrow-right"></i>
</span>
</div>
</div>
<script type="text/javascript" src="js/vender${('.min', '')[app.DEVELOPER]}.js?${sbPID}"></script>
<script type="text/javascript" src="js/lib/bootstrap-formhelpers.min.js?${sbPID}"></script>
Expand Down Expand Up @@ -125,9 +143,11 @@
<script src="js/lib/vue-native-websocket-2.0.7.js"></script>
<script src="js/notifications.js"></script>
<script src="js/store.js"></script>

<script>
Vue.component('app-link', httpVueLoader('js/templates/app-link.vue'));
</script>
<%include file="/vue-components/app-footer.mako"/>
<%include file="/vue-components/asset.mako"/>
<%include file="/vue-components/file-browser.mako"/>
<%include file="/vue-components/plot-info.mako"/>
Expand Down
Loading

0 comments on commit 29e4ce5

Please sign in to comment.