junkie 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,6 +11,7 @@ module Junkie
11
11
 
12
12
  DEFAULT_CONFIG = {
13
13
  watchdog_refresh: 10, # interval the watchdog_timer is fired
14
+ dont_add_episodes_to_queue: false,
14
15
  }
15
16
 
16
17
  def initialize(channels)
@@ -27,13 +28,13 @@ module Junkie
27
28
  @ready_for_new_links = true
28
29
  @watchdog_enabled = false
29
30
  @skipped_timer_at_first_complete_detection = false
31
+ @should_stat_queued_episodes = false
30
32
 
31
33
  @channels[:episodes].subscribe do |episode|
32
34
  next unless episode.status == :found
33
35
 
34
36
  log.info("Got episode from Channel: #{episode}")
35
37
  @found_episodes.push(episode)
36
- stat_queued_episodes
37
38
  end
38
39
  end
39
40
 
@@ -51,7 +52,14 @@ module Junkie
51
52
  EM.add_periodic_timer(@config[:watchdog_refresh]) do
52
53
  monitor_progress if @watchdog_enabled
53
54
 
54
- in_fiber { add_next_episode_to_pyload }
55
+ if @should_stat_queued_episodes
56
+ stat_queued_episodes
57
+ @should_stat_queued_episodes = false
58
+ end
59
+
60
+ if not @config[:dont_add_episodes_to_queue]
61
+ in_fiber { add_next_episode_to_pyload }
62
+ end
55
63
  end
56
64
  end
57
65
 
@@ -91,7 +99,8 @@ module Junkie
91
99
  @channels[:info].push({
92
100
  key: "Pending episodes",
93
101
  desc: "Number of episodes queued for download",
94
- value: @found_episodes.size
102
+ value: @found_episodes.size,
103
+ additional: @found_episodes.map { |e| e.to_s }
95
104
  })
96
105
  end
97
106
 
@@ -1,3 +1,3 @@
1
1
  module Junkie
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12"
3
3
  end
@@ -0,0 +1,73 @@
1
+ function format_stat(stat, internal_page_id) {
2
+ internal_page_id = internal_page_id || ""
3
+
4
+ return '<li data-key="' + stat.key + '">' +
5
+ '<a href="#' + internal_page_id + '" data-ajax="false">' +
6
+ '<span class="ui-li-heading">' + stat.key +
7
+ '</span><span class="ui-li-desc">' + stat.desc +
8
+ '</span><span class="ui-li-count bigger">' + stat.value +
9
+ '</span></a></li>';
10
+ }
11
+
12
+ function format_inpage(stat, inpage_id) {
13
+ var s = $('#_InpageDataTemplate').clone();
14
+
15
+ $(s).attr('id', inpage_id);
16
+ $(s).data('url', inpage_id);
17
+ $('.header', s).text(stat.key);
18
+ $(stat.additional).each(function(index, value) {
19
+ $('.content', s).append('<li>' + value + '</li>');
20
+ });
21
+
22
+ return s;
23
+ }
24
+
25
+ function addOrUpdateStat(stat) {
26
+
27
+ // check if the stat contains additional data that should be
28
+ // displayed in a sub listview
29
+ var inpage_id = "";
30
+ var has_inpage = false;
31
+
32
+ if (stat.additional !== undefined) {
33
+ inpage_id = stat.key.replace(/ /g, '');
34
+ has_inpage = true;
35
+ }
36
+
37
+ var statHtml = format_stat(stat, inpage_id);
38
+
39
+ // add or update the stat in the DOM
40
+ $('#main_page #data li[data-key="' + stat.key + '"]').remove();
41
+ $(statHtml).insertAfter('#stats');
42
+ $('#main_page #data').listview('refresh');
43
+
44
+ // add or update the inpage for additional data if available
45
+ if (has_inpage) {
46
+ var additionalPageHtml = format_inpage(stat, inpage_id);
47
+ $('body #' + inpage_id).remove();
48
+ $('body').append(additionalPageHtml);
49
+ }
50
+ }
51
+
52
+ function updateUpdatedAt() {
53
+ var time = new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1");
54
+ $("#last_update").text(time);
55
+ }
56
+
57
+ $(function () {
58
+ var ws = new WebSocket('ws://' + window.location.host + window.location.pathname);
59
+ ws.onopen = function() {
60
+ console.log('websocket opened');
61
+ $('#connection_status').text('connected');
62
+ };
63
+ ws.onclose = function() {
64
+ console.log('websocket closed');
65
+ $('#connection_status').text('disconnected');
66
+ };
67
+ ws.onmessage = function(m) {
68
+ console.log(m);
69
+ updateUpdatedAt();
70
+ var obj = $.parseJSON(m.data);
71
+ addOrUpdateStat(obj);
72
+ };
73
+ });
@@ -3,29 +3,28 @@
3
3
  <head>
4
4
  <meta charset="utf-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1" />
6
- <title>
7
- </title>
6
+ <title>Junkie Webapp</title>
8
7
  <link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/jquery.mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
9
8
  <style>
10
9
  .bigger {
11
10
  font-size: 100% !important;
12
11
  }
13
12
  </style>
14
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
15
- </script>
16
- <script src="https://ajax.aspnetcdn.com/ajax/jquery.mobile/1.2.0/jquery.mobile-1.2.0.min.js">
17
- </script>
13
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
14
+ <script src="https://ajax.aspnetcdn.com/ajax/jquery.mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
15
+ <script src="/js/index.js"></script>
18
16
  </head>
19
17
  <body>
20
- <!-- Home -->
21
- <div data-role="page" id="page1">
18
+
19
+ <!-- Main page -->
20
+ <div data-role="page" id="main_page">
22
21
  <div data-theme="a" data-role="header">
23
22
  <h3 id="header_title">
24
23
  Junkie Webapp (<%= @junkie_version %>)
25
24
  </h3>
26
25
  </div>
27
26
  <div data-role="content">
28
- <ul data-role="listview" id="data">
27
+ <ul data-role="listview" data-inset="true" id="data">
29
28
  <li data-role="list-divider" id="stats">Stats</li>
30
29
 
31
30
  <li data-role="list-divider">About</li>
@@ -35,45 +34,16 @@
35
34
  </ul>
36
35
  </div>
37
36
  </div>
38
- </body>
39
-
40
- <script type="text/javascript">
41
-
42
- function format_stat(stat) {
43
- return '<li data-key="' + stat.key +
44
- '"><span class="ui-li-heading">' + stat.key +
45
- '</span><span class="ui-li-desc">' + stat.desc +
46
- '</span><span class="ui-li-count bigger">' + stat.value +
47
- '</span></li>';
48
- }
49
-
50
- function addOrUpdateStat(stat) {
51
- var statHtml = format_stat(stat);
52
- $('li[data-key="' + stat.key + '"]').remove();
53
- $(statHtml).insertAfter('#stats');
54
- $('#data').listview('refresh');
55
- }
56
-
57
- function updateUpdatedAt() {
58
- var time = new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1");
59
- $("#last_update").text(time);
60
- }
61
37
 
62
- $(function () {
63
- var ws = new WebSocket('ws://' + window.location.host + window.location.pathname);
64
- ws.onopen = function() {
65
- console.log('websocket opened');
66
- $('#connection_status').text('connected');
67
- };
68
- ws.onclose = function() {
69
- console.log('websocket closed');
70
- $('#connection_status').text('disconnected');
71
- };
72
- ws.onmessage = function(m) {
73
- updateUpdatedAt();
74
- var obj = $.parseJSON(m.data);
75
- addOrUpdateStat(obj);
76
- };
77
- });
78
- </script>
38
+ <!-- Template that is cloned fo all stats that carry additional data-->
39
+ <div data-role="page" id="_InpageDataTemplate">
40
+ <div data-theme="b" data-role="header">
41
+ <h3 class="header"></h3>
42
+ </div>
43
+ <div data-role="content">
44
+ <ul data-role="listview" data-inset="true" class="content">
45
+ </ul>
46
+ </div>
47
+ </div>
48
+ </body>
79
49
  </html>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: junkie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-24 00:00:00.000000000 Z
12
+ date: 2012-12-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine
@@ -249,6 +249,7 @@ files:
249
249
  - lib/junkie/reactor.rb
250
250
  - lib/junkie/version.rb
251
251
  - lib/junkie/webinterface/interface.rb
252
+ - lib/junkie/webinterface/public/js/index.js
252
253
  - lib/junkie/webinterface/views/index.erb
253
254
  - spec/config_spec.rb
254
255
  - spec/environment_spec.rb