From 03d3eb1720286c58c10b660e225a2288292ef2b2 Mon Sep 17 00:00:00 2001 From: Twishi Sagwal Date: Mar 19 2018 22:55:55 +0000 Subject: [PATCH 1/4] Added Facebook Tagged Updates of @TheFedoraProject --- diff --git a/config.xml b/config.xml index f65f371..2dc3eb0 100644 --- a/config.xml +++ b/config.xml @@ -56,11 +56,11 @@ - + diff --git a/package.json b/package.json index fff71cb..728be40 100644 --- a/package.json +++ b/package.json @@ -48,14 +48,14 @@ "cordova-plugin-splashscreen": "^3.2.2", "cordova-plugin-statusbar": "^2.1.3", "cordova-plugin-whitelist": "^1.2.2", - "cordova-plugin-x-socialsharing": "^5.1.8", + "cordova-plugin-x-socialsharing": "^5.3.2", "cordova-plugin-x-toast": "^2.5.2", "es6-promise-plugin": "^4.2.2", "fb": "^1.1.1", "ionic-angular": "3.9.2", "ionic-plugin-keyboard": "^2.2.1", "ionicons": "^3.0.0", - "lodash": "^4.14.0", + "lodash": "^4.17.5", "moment": "^2.14.1", "moment-timezone": "^0.5.5", "query-string": "^4.2.2", @@ -66,6 +66,7 @@ }, "devDependencies": { "@ionic/app-scripts": "3.1.8", + "@types/lodash": "4.14.105", "typescript": "2.4.2" }, "cordova": { diff --git a/src/pages/social/social.ts b/src/pages/social/social.ts index 4af236f..06f0986 100644 --- a/src/pages/social/social.ts +++ b/src/pages/social/social.ts @@ -20,18 +20,22 @@ export class SocialPage { // TODO: Refactor, we are not supposed to use `any`, rather, ww should define an // interface Post { content:string, date:Date } private posts:Array; + private tagged_updates:Array; private tweets:Array; private updates:Array; private USER:any; - + constructor(private browser:Browser, private fb:FB, private tw:Tw, private socialSharing:SocialSharing) { this.posts = []; + this.tagged_updates = []; this.tweets = []; this.updates = []; + this.USER = { FB: 'fedoraqa', + FB2: 'TheFedoraProject', TW: 'fedora_qa', }; } @@ -48,6 +52,13 @@ export class SocialPage { this.mergeUpdates(); }).catch((err) => console.log(err + "kanika")); + this.fb + .getTaggedPosts(this.USER.FB2) + .then((posts:Array) => { + this.tagged_updates = posts; + this.mergeUpdates(); + }).catch((err) => console.log(err + "twishi")); + this.tw .getTimelineTweets(this.USER.TW) .then((tweets:Array) => { @@ -58,7 +69,7 @@ export class SocialPage { mergeUpdates() { // TODO: Merge as per ascending order of timestamps? - this.updates = [ ...this.posts, ...this.tweets ]; + this.updates = [ ...this.posts, ...this.tagged_updates, ...this.tweets ]; } openUpdate(event) { diff --git a/src/providers/fb/fb.ts b/src/providers/fb/fb.ts index a593233..e78c461 100644 --- a/src/providers/fb/fb.ts +++ b/src/providers/fb/fb.ts @@ -10,6 +10,12 @@ const FB_CONFIG = { version: 'v2.6' }; +const FB_CONFIG2 = { + accessToken: 'ACCESS_TOKEN_FOR_PAGE_THEFEDORAPROJECT', + xfbml: true, + version: 'v2.6' +}; + /* Generated class for the Fb provider. @@ -19,8 +25,11 @@ const FB_CONFIG = { @Injectable() export class FB { private fb:Facebook; + private fb2:Facebook; + constructor() { this.fb = new Facebook(FB_CONFIG); + this.fb2 = new Facebook(FB_CONFIG2); } api(urlParts) { @@ -34,6 +43,18 @@ export class FB { }); }); } + + api2(urlParts) { + return new Promise((resolve, reject) => { + this.fb.api(urlParts.join('/'), res => { + if (!res || res.error) { + return reject(res); + } else { + return resolve(res); + } + }); + }); + } getPagePosts(page) { return new Promise((resolve, reject) => { @@ -57,4 +78,27 @@ export class FB { }).catch(reject); }); } + + getTaggedPosts(page) { + return new Promise((resolve, reject) => { + this.api([page, 'tagged']).then((res:any) => { + var posts = _.compact(_.map(res.data, p => { + var post = { + id: p.id, + link: 'https://facebook.com/' + p.id, + content: p.message, + origin: 'facebook', + }; + + if (_.isEmpty(post.content)) { + return null; + } else { + return post; + } + })); + + return resolve(posts); + }).catch(reject); + }); + } } From 1a377ac0e3492d2f0c200e975e7441bec8cca5a1 Mon Sep 17 00:00:00 2001 From: Twishi Sagwal Date: Mar 21 2018 19:15:20 +0000 Subject: [PATCH 2/4] Removed Repeated Code --- diff --git a/src/pages/social/social.ts b/src/pages/social/social.ts index 06f0986..5fb2c2b 100644 --- a/src/pages/social/social.ts +++ b/src/pages/social/social.ts @@ -50,14 +50,14 @@ export class SocialPage { .then((posts:Array) => { this.posts = posts; this.mergeUpdates(); - }).catch((err) => console.log(err + "kanika")); + }).catch((err) => console.log(err)); this.fb .getTaggedPosts(this.USER.FB2) .then((posts:Array) => { this.tagged_updates = posts; this.mergeUpdates(); - }).catch((err) => console.log(err + "twishi")); + }).catch((err) => console.error(err)); this.tw .getTimelineTweets(this.USER.TW) diff --git a/src/providers/fb/fb.ts b/src/providers/fb/fb.ts index e78c461..21899c7 100644 --- a/src/providers/fb/fb.ts +++ b/src/providers/fb/fb.ts @@ -10,11 +10,6 @@ const FB_CONFIG = { version: 'v2.6' }; -const FB_CONFIG2 = { - accessToken: 'ACCESS_TOKEN_FOR_PAGE_THEFEDORAPROJECT', - xfbml: true, - version: 'v2.6' -}; /* Generated class for the Fb provider. @@ -25,11 +20,9 @@ const FB_CONFIG2 = { @Injectable() export class FB { private fb:Facebook; - private fb2:Facebook; constructor() { this.fb = new Facebook(FB_CONFIG); - this.fb2 = new Facebook(FB_CONFIG2); } api(urlParts) { @@ -44,17 +37,6 @@ export class FB { }); } - api2(urlParts) { - return new Promise((resolve, reject) => { - this.fb.api(urlParts.join('/'), res => { - if (!res || res.error) { - return reject(res); - } else { - return resolve(res); - } - }); - }); - } getPagePosts(page) { return new Promise((resolve, reject) => { From a03e7464a22cc4fd4a65da02479084a4257b7aad Mon Sep 17 00:00:00 2001 From: Twishi Sagwal Date: Mar 21 2018 19:19:54 +0000 Subject: [PATCH 3/4] Removed Repeated Code --- diff --git a/src/pages/social/social.ts b/src/pages/social/social.ts index 5fb2c2b..3c92ba8 100644 --- a/src/pages/social/social.ts +++ b/src/pages/social/social.ts @@ -35,7 +35,7 @@ export class SocialPage { this.USER = { FB: 'fedoraqa', - FB2: 'TheFedoraProject', + FB_TAGGED: ['TheFedoraProject'], TW: 'fedora_qa', }; } @@ -52,12 +52,15 @@ export class SocialPage { this.mergeUpdates(); }).catch((err) => console.log(err)); - this.fb - .getTaggedPosts(this.USER.FB2) + + this.fb + .getTaggedPosts(this.USER.FB_TAGGED[0]) .then((posts:Array) => { this.tagged_updates = posts; this.mergeUpdates(); }).catch((err) => console.error(err)); + + this.tw .getTimelineTweets(this.USER.TW) From d0d0ea2a863e7d8f9b152af32ecee60e88899d26 Mon Sep 17 00:00:00 2001 From: Ashutosh Kumar Date: Mar 27 2018 01:41:22 +0000 Subject: [PATCH 4/4] Implemented OpenID login with skip Login feature --- diff --git a/package.json b/package.json index 728be40..4c05dd1 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "@ionic-native/status-bar": "4.4.0", "@ionic-native/toast": "^4.5.3", "@ionic/storage": "2.1.3", + "angular-oauth2-oidc": "^3.1.4", "cordova-android": "7.0.0", "cordova-browser": "5.0.3", "cordova-plugin-calendar": "^4.5.5", @@ -89,4 +90,4 @@ "android" ] } -} \ No newline at end of file +} diff --git a/src/app/app.component.ts b/src/app/app.component.ts index df270df..5ef1be2 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,3 +1,4 @@ +import { OAuthService } from 'angular-oauth2-oidc'; import {Component, ViewChild} from '@angular/core'; import { Platform, NavController } from 'ionic-angular'; @@ -9,6 +10,9 @@ import {WomenPage} from '../pages/women/women'; import {FirstPage} from '../pages/first/first'; import { SplashScreen } from '@ionic-native/splash-screen'; +import {LoginPage} from '../pages/login/login'; +import {LogoutPage} from '../pages/logout/logout'; + @Component({ templateUrl: 'app.html', }) @@ -19,19 +23,58 @@ export class MyApp { @ViewChild('content') nav:NavController; - constructor(platform:Platform, splashScreen:SplashScreen) { - // used for an example of ngFor and navigation - this.pages = [ - { title: 'Home', component: FirstPage }, - { title: 'Magazine', component: MagazinePage }, - { title: 'Social', component: SocialPage }, - { title: 'Ask', component: AskPage }, - { title: 'Calendar', component: CalendarPage }, - { title: 'Women', component: WomenPage } + constructor(platform:Platform, splashScreen:SplashScreen, oauthService: OAuthService) { + + + + - ]; + let skipLogin = localStorage.getItem("skipLogin"); + let oauth_access_token = localStorage.getItem("access_token"); + if(skipLogin == "1"){ + this.pages = [ + { title: 'Home', component: FirstPage }, + { title: 'Magazine', component: MagazinePage }, + { title: 'Social', component: SocialPage }, + { title: 'Ask', component: AskPage }, + { title: 'Calendar', component: CalendarPage }, + { title: 'Women', component: WomenPage }, + { title: 'Login', component: LoginPage } + ]; + this.rootPage = FirstPage; + } + else{ + if (oauthService.hasValidIdToken() || oauth_access_token.length > 1) { + this.pages = [ + { title: 'Home', component: FirstPage }, + { title: 'Magazine', component: MagazinePage }, + { title: 'Social', component: SocialPage }, + { title: 'Ask', component: AskPage }, + { title: 'Calendar', component: CalendarPage }, + { title: 'Women', component: WomenPage }, + { title: 'Logout', component: LogoutPage } + + ]; + this.rootPage = FirstPage; + } else { + + this.pages = [ + { title: 'Home', component: FirstPage }, + { title: 'Magazine', component: MagazinePage }, + { title: 'Social', component: SocialPage }, + { title: 'Ask', component: AskPage }, + { title: 'Calendar', component: CalendarPage }, + { title: 'Women', component: WomenPage }, + { title: 'Logout', component: LogoutPage } + + + ]; + this.rootPage = LoginPage; + } + + } - this.rootPage = FirstPage; + platform.ready().then(() => { // Okay, so the platform is ready and our plugins are available. diff --git a/src/app/app.module.ts b/src/app/app.module.ts index b5f9309..af8808d 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,7 +1,10 @@ import { BrowserModule } from '@angular/platform-browser'; import { ErrorHandler, NgModule } from '@angular/core'; +import { OAuthService,UrlHelperService } from 'angular-oauth2-oidc'; import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular'; import { HttpClientModule } from '@angular/common/http'; +import { HttpModule } from '@angular/http'; + import { InAppBrowser } from '@ionic-native/in-app-browser'; import { SplashScreen } from '@ionic-native/splash-screen'; import { StatusBar } from '@ionic-native/status-bar'; @@ -20,6 +23,8 @@ import { WomenPage } from '../pages/women/women'; import { Browser } from '../providers/browser/browser'; import { Request } from '../providers/request/request'; import { IonicConfig } from '../providers/ionic-config/ionic-config'; +import {LoginPage} from '../pages/login/login'; +import {LogoutPage} from '../pages/logout/logout'; @NgModule({ declarations: [ @@ -29,10 +34,11 @@ import { IonicConfig } from '../providers/ionic-config/ionic-config'; AskPage, CalendarPage, SocialPage, - WomenPage + WomenPage, LoginPage,LogoutPage ], imports: [ BrowserModule, + HttpModule, HttpClientModule, IonicModule.forRoot(MyApp) ], @@ -44,7 +50,8 @@ import { IonicConfig } from '../providers/ionic-config/ionic-config'; AskPage, CalendarPage, SocialPage, - WomenPage + WomenPage, + LoginPage,LogoutPage ], providers: [ Browser, @@ -56,6 +63,8 @@ import { IonicConfig } from '../providers/ionic-config/ionic-config'; SpinnerDialog, StatusBar, Toast, + UrlHelperService, + OAuthService, { provide: ErrorHandler, useClass: IonicErrorHandler } ] }) diff --git a/src/index.html b/src/index.html index e25bc0b..feafc71 100644 --- a/src/index.html +++ b/src/index.html @@ -26,7 +26,7 @@ .catch(err => console.error('Error', err)); } --> - +