timeline update: ES6, components, refactoring, other
This commit is contained in:
1 parent
761938b17a
commit
73a3361376
20 files changed
+315
-238
No files matched your search
+8
-1
@@ -8,6 +8,10 @@ import Document from './components/Document';
|
||||
import Award from './components/Award';
|
||||
import GalleryItem from './components/GalleryItem';
|
||||
import TeamMemberProfile from './components/TeamMemberProfile';
|
||||
import Timeline from './components/Timeline';
|
||||
import TimelineRecord from './components/TimelineRecord';
|
||||
import TimelineRecordPost from './components/TimelineRecordPost';
|
||||
import TimelineRecordInstagram from './components/TimelineRecordInstagram';
|
||||
import AppController from './controllers/AppController';
|
||||
import HomeController from './controllers/HomeController';
|
||||
import ScheduleController from './controllers/ScheduleController';
|
||||
@@ -106,9 +110,12 @@ app.run(($location, $rootScope, $http) => {
|
||||
RemoveNewline,
|
||||
Strip,
|
||||
UppercaseFirst,
|
||||
require('./ui/timeline'),
|
||||
MainMenu,
|
||||
Breadcrumbs,
|
||||
Timeline,
|
||||
TimelineRecord,
|
||||
TimelineRecordPost,
|
||||
TimelineRecordInstagram,
|
||||
Document,
|
||||
Award,
|
||||
GalleryItem,
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
import template from '../../templates/components/timeline.html';
|
||||
|
||||
function personByInstagram(list, instagram){
|
||||
list = list.filter(function (member) {
|
||||
try {
|
||||
return member.contacts.instagram === instagram;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
if(list.length){
|
||||
return list[0].id;
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function postText(post){
|
||||
try{
|
||||
return post.data.caption.text.replace(/#[\w_]+/, '')
|
||||
}catch(error){
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
export default function(app) {
|
||||
app.component('timeline', {
|
||||
template: template,
|
||||
controller: function($timeout, usSpinnerService, io, api, team){
|
||||
let portion = 0;
|
||||
let count = 10;
|
||||
this.feed = [];
|
||||
|
||||
this.timelineUpdating = false;
|
||||
usSpinnerService.stop('timelineMore');
|
||||
//usSpinnerService.spin("timelineMore");
|
||||
|
||||
function toInstagram(post){
|
||||
var author_id = personByInstagram(team.team, post.data.author);
|
||||
var name = author_id ? team.short(author_id) : post.data.author;
|
||||
|
||||
return {
|
||||
date: post.date,
|
||||
image: post.data.image.standard_resolution.url,
|
||||
url: post.data.url,
|
||||
username: name,
|
||||
userpic: 'https://igcdn-photos-a-a.akamaihd.net/hphotos-ak-xaf1/t51.2885-19/11357496_464997000344800_2124591831_a.jpg',
|
||||
text: post.body,
|
||||
//text: postText(post),
|
||||
type: post.type
|
||||
};
|
||||
}
|
||||
|
||||
this.showFooter = () => this.feed && this.feed.length;
|
||||
|
||||
this.loadNext = () => {
|
||||
this.timelineUpdating = true;
|
||||
usSpinnerService.spin('timelineMore');
|
||||
|
||||
api.news.feed(count, portion)
|
||||
.error(error => {
|
||||
console.log(error);
|
||||
})
|
||||
.success(feed => {
|
||||
this.timelineUpdating = false;
|
||||
usSpinnerService.stop('timelineMore');
|
||||
|
||||
let feed2 = feed.map(post => {
|
||||
if(post.type == 'instagram') return toInstagram(post);
|
||||
else return post;
|
||||
});
|
||||
|
||||
portion++;
|
||||
this.feed = this.feed.concat(feed2);
|
||||
});
|
||||
};
|
||||
|
||||
this.loadNext();
|
||||
|
||||
io.on('post', params => {
|
||||
//let posts = params instanceof Array ? params : [params];
|
||||
//
|
||||
//let feed2 = posts.map(post => {
|
||||
// if(post.type == 'instagram') return toInstagram(post);
|
||||
// else return post;
|
||||
//});
|
||||
|
||||
//this.$apply(() => {
|
||||
// this.feed = feed2.concat(this.feed);
|
||||
//});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
//app.directive("timelineRecord", function ($compile, $http, $sce, team) {
|
||||
// var templates = {
|
||||
// "post": ["/views/timeline-post.html", linkPost],
|
||||
// "instagram": ["/views/timeline-gram.html", linkGram]
|
||||
// };
|
||||
//
|
||||
// function linkPost(scope, element, attrs) {
|
||||
// scope.message = $sce.trustAsHtml(scope.post.body);
|
||||
// }
|
||||
//
|
||||
// function linkGram(scope, element, attrs) {
|
||||
// }
|
||||
//
|
||||
// return {
|
||||
// restrict: "E",
|
||||
// scope: {
|
||||
// post:"=content"
|
||||
// },
|
||||
// link: function(scope, element, attrs){
|
||||
// var type = scope.post.type;
|
||||
// if(type in templates) {
|
||||
// $http.get(templates[type][0])
|
||||
// .success(function (tpl) {
|
||||
// element.html(tpl).show();
|
||||
// $compile(element.contents())(scope);
|
||||
// templates[type][1](scope, element, attrs);
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// };
|
||||
//});
|
||||
};
|
||||
@@ -0,0 +1,11 @@
|
||||
import template from '../../templates/components/timeline-record.html';
|
||||
|
||||
export default function (app) {
|
||||
app.component('timelineRecord', {
|
||||
bindings: {
|
||||
post: '<',
|
||||
type: '@'
|
||||
},
|
||||
template: template
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,10 @@
|
||||
import template from '../../templates/components/timeline-record-instagram.html';
|
||||
|
||||
export default function (app) {
|
||||
app.component('timelineRecordInstagram', {
|
||||
bindings: {
|
||||
post: '<'
|
||||
},
|
||||
template: template
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
import template from '../../templates/components/timeline-record-post.html';
|
||||
|
||||
export default function (app) {
|
||||
app.component('timelineRecordPost', {
|
||||
bindings: {
|
||||
post: '<'
|
||||
},
|
||||
template: template,
|
||||
controller: function($sce){
|
||||
this.message = $sce.trustAsHtml(this.post.body);
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -1,147 +0,0 @@
|
||||
/**
|
||||
* Created by tmshv on 23/11/14.
|
||||
*/
|
||||
|
||||
function personByInstagram(list, instagram){
|
||||
list = list.filter(function (member) {
|
||||
try {
|
||||
return member.contacts.instagram === instagram;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
if(list.length){
|
||||
return list[0].id;
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function postText(post){
|
||||
try{
|
||||
return post.data.caption.text.replace(/#[\w_]+/, "")
|
||||
}catch(error){
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = function(app) {
|
||||
app.directive("timeline", function (team) {
|
||||
function toInstagram(post){
|
||||
var author_id = personByInstagram(team.team, post.data.author);
|
||||
var name = author_id ? team.short(author_id) : post.data.author;
|
||||
|
||||
return {
|
||||
date: post.date,
|
||||
image: post.data.image.standard_resolution.url,
|
||||
url: post.data.url,
|
||||
username: name,
|
||||
userpic: 'https://igcdn-photos-a-a.akamaihd.net/hphotos-ak-xaf1/t51.2885-19/11357496_464997000344800_2124591831_a.jpg',
|
||||
text: post.body,
|
||||
//text: postText(post),
|
||||
type: post.type
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
templateUrl: "/views/timeline.html",
|
||||
scope: {
|
||||
|
||||
},
|
||||
link: function(scope, element, attrs){
|
||||
scope.isEven = function(index){
|
||||
return index % 2 === 1;
|
||||
}
|
||||
},
|
||||
controller: function($scope, $timeout, usSpinnerService, io, api){
|
||||
var portion = 0;
|
||||
var count = 10;
|
||||
$scope.feed = [];
|
||||
|
||||
$scope.timelineUpdating = false;
|
||||
usSpinnerService.stop("timelineMore");
|
||||
//usSpinnerService.spin("timelineMore");
|
||||
|
||||
$scope.recordClass = function (i) {
|
||||
return i['type'];
|
||||
};
|
||||
|
||||
$scope.showFooter = function () {
|
||||
var canLoadMore = true;
|
||||
return $scope.feed && $scope.feed.length && canLoadMore;
|
||||
};
|
||||
|
||||
$scope.loadNext = function () {
|
||||
$scope.timelineUpdating = true;
|
||||
usSpinnerService.spin("timelineMore");
|
||||
|
||||
api.news.feed(count, portion)
|
||||
.error(function(error) {
|
||||
console.log(error);
|
||||
})
|
||||
.success(function (list) {
|
||||
$scope.timelineUpdating = false;
|
||||
usSpinnerService.stop("timelineMore");
|
||||
|
||||
var feed = list.map(function (post) {
|
||||
if(post.type == "instagram") return toInstagram(post);
|
||||
else return post;
|
||||
});
|
||||
|
||||
portion++;
|
||||
$scope.feed = $scope.feed.concat(feed);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.loadNext();
|
||||
|
||||
io.on("post", function (params) {
|
||||
var posts = params instanceof Array ? params : [params];
|
||||
|
||||
var feed = posts.map(function (post) {
|
||||
if(post.type == "instagram") return toInstagram(post);
|
||||
else return post;
|
||||
});
|
||||
|
||||
$scope.$apply(function () {
|
||||
$scope.feed = feed.concat($scope.feed);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
app.directive("timelineRecord", function ($compile, $http, $sce, team) {
|
||||
var templates = {
|
||||
"post": ["/views/timeline-post.html", linkPost],
|
||||
"instagram": ["/views/timeline-gram.html", linkGram]
|
||||
};
|
||||
|
||||
function linkPost(scope, element, attrs) {
|
||||
scope.message = $sce.trustAsHtml(scope.post.body);
|
||||
}
|
||||
|
||||
function linkGram(scope, element, attrs) {
|
||||
}
|
||||
|
||||
return {
|
||||
restrict: "E",
|
||||
scope: {
|
||||
post:"=content"
|
||||
},
|
||||
link: function(scope, element, attrs){
|
||||
var type = scope.post.type;
|
||||
if(type in templates) {
|
||||
$http.get(templates[type][0])
|
||||
.success(function (tpl) {
|
||||
element.html(tpl).show();
|
||||
$compile(element.contents())(scope);
|
||||
templates[type][1](scope, element, attrs);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
});
|
||||
};
|
||||
Reference in new issue
Block a user