Merge branch '#1' into 'master'
#1 See merge request martind2000/jubilee!1
This commit is contained in:
commit
b08ede316f
@ -42,9 +42,11 @@ function doGetEuroNews() {
|
||||
return new Promise((resolve, reject) => {
|
||||
logger.info('Retrieving Euronews Headlines..');
|
||||
|
||||
// http://feeds.feedburner.com/euronews/en/home/
|
||||
// http://feeds.feedburner.com/euronews/en/news/
|
||||
const options = {
|
||||
'hostname': 'feeds.feedburner.com',
|
||||
'path': '/euronews/en/news/',
|
||||
'path': '/euronews/en/home/',
|
||||
'method': 'GET',
|
||||
'headers': headers
|
||||
};
|
||||
|
@ -299,10 +299,10 @@ li {
|
||||
}
|
||||
|
||||
#newsShell {
|
||||
height:225px;
|
||||
/* height:225px;*/
|
||||
}
|
||||
#news{
|
||||
height: 275px;
|
||||
height: 200px;
|
||||
margin-top:15px;
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
const CACHE_VERSION = { 'version': '0.0.401' };
|
||||
const CACHE_VERSION = { 'version': '0.0.477' };
|
||||
const dataCacheName = 'jubileeData-v1';
|
||||
const cacheName = 'jubilee-final-1';
|
||||
const filesToCache = [
|
||||
|
@ -63,6 +63,9 @@
|
||||
<div id="newsShell" class="mui-panel" style="display: none;">
|
||||
<div class="mui--text-title cardTitle">Latest news</div>
|
||||
<div id="news" class="scrolling-wrapper-flexbox"></div>
|
||||
<div id='newsMore' class="cardLink">
|
||||
<i class="seemore material-icons mui--align-middle " >arrow_forward</i> <span class="seemore mui--align-middle">More news</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="weatherShell" class="mui-panel" style="display: none;">
|
||||
|
@ -104,6 +104,14 @@ const NewsModel = Backbone.Model.extend({
|
||||
|
||||
const NewsView = Backbone.View.extend({
|
||||
'className': '',
|
||||
'template': _.template(`
|
||||
<div class="mui--text-title cardTitle">Latest news</div>
|
||||
<div id="news" class="scrolling-wrapper-flexbox"></div>
|
||||
<div id='newsMore' class="cardLink">
|
||||
<i class="seemore material-icons mui--align-middle " >arrow_forward</i> <span class="seemore mui--align-middle">More news</span>
|
||||
</div>
|
||||
`),
|
||||
|
||||
'initialize': function(options) {
|
||||
this.eventBus = options.eventBus;
|
||||
this.newsCollection = newsCollection;
|
||||
@ -127,15 +135,21 @@ const NewsView = Backbone.View.extend({
|
||||
|
||||
this.$el.empty();
|
||||
|
||||
this.$el.append(this.template());
|
||||
|
||||
this.$news = this.$el.find('#news');
|
||||
|
||||
this.newsCollection.each(function(item) {
|
||||
const niView = new newsItemView({ 'model': item });
|
||||
this.$el.append(niView.el);
|
||||
|
||||
this.$news.append(niView.el);
|
||||
}, this);
|
||||
|
||||
this.$el.parent().show();
|
||||
// console.log(this.$el.parent());
|
||||
this.$el.show();
|
||||
}, 'events': {
|
||||
'click #newsMore': 'doMoreNews',
|
||||
'click .scrollCard': 'doClick'
|
||||
|
||||
}, 'doClick': function(d) {
|
||||
console.log('Do click', d);
|
||||
const id = get(d, 'currentTarget.dataset.guid', '');
|
||||
@ -150,6 +164,11 @@ const NewsView = Backbone.View.extend({
|
||||
|
||||
if (since > (60 * 1000 * 60) )
|
||||
this.model.set('update', now);
|
||||
},
|
||||
'doMoreNews': function() {
|
||||
console.log('doMoreNews', this);
|
||||
|
||||
this.eventBus.trigger('showNewsList');
|
||||
}
|
||||
});
|
||||
|
||||
|
143
src/v1/js/NewsList.js
Normal file
143
src/v1/js/NewsList.js
Normal file
@ -0,0 +1,143 @@
|
||||
const $ = require('jquery');
|
||||
const _ = require('underscore');
|
||||
const Backbone = require('backbone');
|
||||
const request = require('request');
|
||||
const { get } = require('lodash');
|
||||
const { reduceEuronews } = require('./libs/reducers');
|
||||
const { createPanel, addPanel } = require('./libs/panel');
|
||||
|
||||
const NewsItem = Backbone.Model.extend({
|
||||
|
||||
});
|
||||
|
||||
const NewsCollection = Backbone.Collection.extend({
|
||||
'model': NewsItem
|
||||
});
|
||||
|
||||
const newsCollection = new NewsCollection();
|
||||
|
||||
const NewsItemView = Backbone.View.extend({
|
||||
'tagName': 'div',
|
||||
'className' : 'newsItem',
|
||||
'template': _.template(`
|
||||
|
||||
<div class="mui--text-subhead mui--text-accent"><%=title%></div>
|
||||
<div class="published mui--text-dark-secondary mui--text-caption"><%=pubdate%></div>
|
||||
|
||||
<p class="mui--text-body1"><%=description%></p>
|
||||
|
||||
`),
|
||||
'initialize': function() {
|
||||
this.render();
|
||||
},
|
||||
'attributes': function() {
|
||||
return {
|
||||
'data-guid': this.model.get('guid')
|
||||
};
|
||||
},
|
||||
|
||||
'render': function() {
|
||||
this.$el.html(this.template(this.model.toJSON()));
|
||||
}
|
||||
});
|
||||
|
||||
const NewsListModel = Backbone.Model.extend({
|
||||
'defaults' : function (obj) {
|
||||
// return a new object
|
||||
return {
|
||||
'update' : new Date().getTime()
|
||||
};
|
||||
}, 'initialize': function() {
|
||||
this.newsCollection = newsCollection;
|
||||
this.listenTo(this, 'change:update', this.onChange);
|
||||
this.getNews();
|
||||
},
|
||||
'onChange': function() {
|
||||
this.getNews();
|
||||
},
|
||||
'getNews': function() {
|
||||
console.info('>> News:request');
|
||||
request({
|
||||
'url': `${window.loc}/news`,
|
||||
'method': 'GET', 'qs': {
|
||||
|
||||
}
|
||||
}, function(err, res, body) {
|
||||
if (err)
|
||||
console.error(err);
|
||||
else {
|
||||
console.log('statusCode', res.statusCode);
|
||||
const fsJSON = JSON.parse(body);
|
||||
// console.log(body);
|
||||
const newItems = [];
|
||||
|
||||
for (const item of fsJSON.items)
|
||||
newItems.push(reduceEuronews(item));
|
||||
|
||||
this.newsCollection.reset(newItems);
|
||||
|
||||
this.logUpdate();
|
||||
}
|
||||
}.bind(this));
|
||||
}, 'logUpdate': function() {
|
||||
console.log('News logging:');
|
||||
|
||||
const time = new Date().getTime() ;
|
||||
|
||||
this.set('time', time);
|
||||
|
||||
this.timerID = setTimeout(
|
||||
() => this.tick(),
|
||||
3.6e+6 + 1000
|
||||
);
|
||||
},
|
||||
'tick': function() {
|
||||
console.log('Set update');
|
||||
this.set('update', new Date().getTime());
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
const NewsListView = Backbone.View.extend({
|
||||
'initialize': function(options) {
|
||||
this.eventBus = options.eventBus;
|
||||
|
||||
_.bindAll(this, 'doClick');
|
||||
|
||||
this.model.newsCollection.bind('reset', this.render, this);
|
||||
this.eventBus.on('showNewsList', this.showNewsListPanel, this);
|
||||
},
|
||||
'showNewsListPanel': function() {
|
||||
console.log('Showing news list');
|
||||
|
||||
this.model.set('update', new Date().getTime());
|
||||
this.$newPanel = createPanel({ 'title':'More news', 'divId':'newsListP' });
|
||||
|
||||
this.$el = addPanel(this.$newPanel);
|
||||
|
||||
this.$el.empty();
|
||||
this.$newPanel.show();
|
||||
}, 'events': {
|
||||
'click': 'doClick'
|
||||
|
||||
}, 'doClick': function(d) {
|
||||
console.log('Do click', d);
|
||||
const id = get(d, 'currentTarget.dataset.guid', '');
|
||||
console.log(id);
|
||||
this.eventBus.trigger('showNews', id);
|
||||
},
|
||||
'render' : function() {
|
||||
console.log('>> Do render');
|
||||
|
||||
this.model.newsCollection.each(function(item) {
|
||||
const niView = new NewsItemView({ 'model': item });
|
||||
|
||||
this.$el.append(niView.el);
|
||||
}, this);
|
||||
|
||||
this.$el.find('.newsItem').on('click', this.doClick);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = { NewsListModel, NewsListView };
|
@ -31,7 +31,7 @@ const NewsCardModel = Backbone.Model.extend({
|
||||
// console.log(fsJSON);
|
||||
|
||||
this.set('article', fsJSON);
|
||||
console.log(body);
|
||||
// console.log(body);
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
|
@ -12,12 +12,13 @@ const { WeatherAlertModel, WeatherAlertView } = require('./WeatherAlert');
|
||||
const { ForecastModel, ForecastView } = require('./Forecast');
|
||||
const { NewsModel, NewsView } = require('./News');
|
||||
const { NewsCardModel, NewsCardView } = require('./NewsViewer');
|
||||
const { NewsListModel, NewsListView } = require('./NewsList');
|
||||
const { ByMeModel, ByMeView } = require('./RightByMe');
|
||||
const { AgendaModel, AgendaView } = require('./Agenda');
|
||||
const { TrafficModel, TrafficView } = require('./Traffic');
|
||||
var app = app || {};
|
||||
|
||||
const live = true;
|
||||
const live = false;
|
||||
|
||||
if (live) {
|
||||
window.loc = 'https://jubilee.silvrtree.co.uk';
|
||||
@ -59,7 +60,9 @@ else
|
||||
|
||||
app.newsCard = new NewsCardView({ 'model': new NewsCardModel(), 'eventBus': app.eventBus });
|
||||
|
||||
app.news = new NewsView({ 'model': new NewsModel(), 'eventBus': app.eventBus, 'el':'#news' });
|
||||
app.newsList = new NewsListView({'model': new NewsListModel(), 'eventBus' : app.eventBus});
|
||||
|
||||
app.news = new NewsView({ 'model': new NewsModel(), 'eventBus': app.eventBus, 'el':'#newsShell' });
|
||||
|
||||
app.byMe = new ByMeView({ 'model': new ByMeModel(), 'eventBus': app.eventBus, 'location': app.locationModel, 'el':'#byme' });
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user