Skip to content

Commit

Permalink
(feat): working thumbs on cards
Browse files Browse the repository at this point in the history
  • Loading branch information
markharding committed Jan 10, 2017
1 parent 752723e commit 5e36f40
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 35 deletions.
8 changes: 7 additions & 1 deletion src/app/common/services/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export class Client {
base : string = "https://edge.minds.com/";
oauth2;

storage = new Storage();

constructor(public http : Http){
this.oauth2 = new OAuth2(http);
}
Expand All @@ -34,7 +36,9 @@ export class Client {
});*/

var Objecti : any = Object;
return Objecti.assign(options, {});
return Objecti.assign(options, {
access_token: this.storage.get('access_token')
});
}

/**
Expand Down Expand Up @@ -102,6 +106,7 @@ export class Client {
*/
put(endpoint : string, data : Object = {}, options: Object = {}){
var self = this;
endpoint += "?" + this.buildParams({});
return new Promise((resolve, reject) => {
self.http.put(
self.base + endpoint,
Expand Down Expand Up @@ -133,6 +138,7 @@ export class Client {
*/
delete(endpoint : string, data : Object = {}, options: Object = {}){
var self = this;
endpoint += "?" + this.buildParams({});
return new Promise((resolve, reject) => {
self.http.delete(
self.base + endpoint,
Expand Down
3 changes: 0 additions & 3 deletions src/app/modules/buttons/remind.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export class RemindButtonComponent {
entity = {
'guid': null,
'owner_guid': null,
'thumbs:up:user_guids': []
};

constructor(public client : Client) {
Expand All @@ -28,8 +27,6 @@ export class RemindButtonComponent {
if(!value)
return;
this.entity = value;
if(!this.entity['thumbs:up:user_guids'])
this.entity['thumbs:up:user_guids'] = [];
}


Expand Down
45 changes: 41 additions & 4 deletions src/app/modules/buttons/thumbsdown.component.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { Component, ChangeDetectionStrategy, Input } from '@angular/core';

import { Client } from '../../common/services/api/client';
import { Storage } from '../../common/services/storage';


@Component({
moduleId: 'module.id',
selector: 'minds-button-thumbs-down',
changeDetection: ChangeDetectionStrategy.OnPush,
host: {
'(click)': 'thumb()'
},
template: `
<ion-icon name="md-thumbs-down" class="m-ionic-icon"></ion-icon>
<ion-icon name="md-thumbs-down" class="m-ionic-icon" [class.selected]="has()"></ion-icon>
`,
//styleUrls: ['buttons.css']
})
Expand All @@ -18,18 +22,51 @@ export class ThumbsDownComponent {
entity = {
'guid': null,
'owner_guid': null,
'thumbs:up:user_guids': []
'thumbs:down:user_guids': []
};

storage = new Storage();

constructor(public client : Client) {
}

@Input('entity') set _entity(value : any){
if(!value)
return;
this.entity = value;
if(!this.entity['thumbs:up:user_guids'])
this.entity['thumbs:up:user_guids'] = [];
if(!this.entity['thumbs:down:user_guids'])
this.entity['thumbs:down:user_guids'] = [];
}

thumb(){
var self = this;

this.client.put('api/v1/thumbs/' + this.entity.guid + '/down', {});
if(!this.has()){
//this.entity['thumbs:up:user_guids'].push(this.session.getLoggedInUser().guid);
this.entity['thumbs:down:user_guids'] = [ this.storage.get('user_guid') ];
this.entity['thumbs:down:count']++;
if ( this.storage.get('user_guid') != this.entity.owner_guid) {
//self.wallet.increment();
}
} else {
for(let key in this.entity['thumbs:down:user_guids']){
if(this.entity['thumbs:down:user_guids'][key] == this.storage.get('user_guid'))
delete this.entity['thumbs:down:user_guids'][key];
}
this.entity['thumbs:down:count']--;
if ( this.storage.get('user_guid')!= this.entity.owner_guid) {
//self.wallet.decrement();
}
}
}

has(){
for(var guid of this.entity['thumbs:down:user_guids']){
if(guid == this.storage.get('user_guid'))
return true;
}
return false;
}

}
48 changes: 24 additions & 24 deletions src/app/modules/buttons/thumbsup.component.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { Component, ChangeDetectionStrategy, Input } from '@angular/core';

import { Client } from '../../common/services/api/client';
import { Storage } from '../../common/services/storage';


@Component({
moduleId: 'module.id',
selector: 'minds-button-thumbs-up',
changeDetection: ChangeDetectionStrategy.OnPush,
host: {
'(click)': 'thumb()'
},
template: `
<ion-icon name="md-thumbs-up" class="m-ionic-icon selected"></ion-icon>
<ion-icon name="md-thumbs-up" class="m-ionic-icon" [class.selected]="has()"></ion-icon>
`,
//styleUrls: [ 'buttons.css' ]
})
Expand All @@ -21,6 +25,8 @@ export class ThumbsUpComponent {
'thumbs:up:user_guids': []
};

storage = new Storage();

constructor(public client : Client) {
}

Expand All @@ -35,37 +41,31 @@ export class ThumbsUpComponent {
thumb(){
var self = this;

/*if(!this.session.isLoggedIn()){
this.modal.setSubtitle("You need to have a channel to vote").open();
this.showModal = true;
return false;
}
this.client.put('api/v1/thumbs/' + this.object.guid + '/up', {});
this.client.put('api/v1/thumbs/' + this.entity.guid + '/up', {});
if(!this.has()){
//this.object['thumbs:up:user_guids'].push(this.session.getLoggedInUser().guid);
this.object['thumbs:up:user_guids'] = [this.session.getLoggedInUser().guid];
this.object['thumbs:up:count']++;
if (this.session.getLoggedInUser().guid != this.object.owner_guid) {
self.wallet.increment();
//this.entity['thumbs:up:user_guids'].push(this.session.getLoggedInUser().guid);
this.entity['thumbs:up:user_guids'] = [ this.storage.get('user_guid') ];
this.entity['thumbs:up:count']++;
if ( this.storage.get('user_guid') != this.entity.owner_guid) {
//self.wallet.increment();
}
} else {
for(let key in this.object['thumbs:up:user_guids']){
if(this.object['thumbs:up:user_guids'][key] == this.session.getLoggedInUser().guid)
delete this.object['thumbs:up:user_guids'][key];
for(let key in this.entity['thumbs:up:user_guids']){
if(this.entity['thumbs:up:user_guids'][key] == this.storage.get('user_guid'))
delete this.entity['thumbs:up:user_guids'][key];
}
this.object['thumbs:up:count']--;
if (this.session.getLoggedInUser().guid != this.object.owner_guid) {
self.wallet.decrement();
this.entity['thumbs:up:count']--;
if ( this.storage.get('user_guid')!= this.entity.owner_guid) {
//self.wallet.decrement();
}
}*/
}
}

has(){
/*for(var guid of this.entity['thumbs:up:user_guids']){
//if(guid == this.session.getLoggedInUser().guid)
// return true;
}*/
for(var guid of this.entity['thumbs:up:user_guids']){
if(guid == this.storage.get('user_guid'))
return true;
}
return false;
}

Expand Down
4 changes: 4 additions & 0 deletions src/app/modules/newsfeed/activity/activity.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
color: #333;
text-decoration:none;
}

span{
font-size:11px;
}
}

.m-ionic-avatar{
Expand Down
6 changes: 3 additions & 3 deletions src/app/modules/newsfeed/list.component.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<ion-header>
<ion-navbar>
<ion-title>
<img src="https://www.minds.com/icon/me/small"
width="32"
height="32"
<img [src]="'https://www.minds.com/icon/' + storage.get('user_guid') +'/small'"
width="40"
height="40"
style="border-radius:50%"
[navPush]="components.channel"
[navParams]="{ guid: 'me' }"/>
Expand Down
4 changes: 4 additions & 0 deletions src/app/modules/newsfeed/list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Component, OnInit, OnDestroy, Input, ChangeDetectionStrategy, ChangeDet

import { ChannelComponent } from '../channel/channel.component';
import { Client } from '../../common/services/api/client';
import { Storage } from '../../common/services/storage';


@Component({
moduleId: 'module.id',
Expand All @@ -17,6 +19,8 @@ export class NewsfeedList {
offset : string = "";
inProgress : boolean = true;

storage = new Storage();

components = {
channel: ChannelComponent
}
Expand Down

0 comments on commit 5e36f40

Please sign in to comment.