'use strict' ; import { View , IScope } from '../index' ; import { isWechatBrowser } from '../../components/services/utils/isWechat' ; export class BannerView extends View { public static $inject = [ '$scope' ] ; protected $state : angular . ui . IStateService ; private _isWechat = isWechatBrowser ( ) ; private _isAndroid = navigator . platform !== 'iPhone' && navigator . userAgent . indexOf ( 'Android' ) !== - 1 ; private _isIPhone = navigator . platform === 'iPhone' || navigator . platform === 'iPad' ; private _browserVersion : string ; private _magicLink = 'https://magiclink.teambition.com/share/' ; private _urlSchema = 'teambition://' ; private _androidSchema = 'http://a.app.qq.com/o/simple.jsp?pkgname=com.teambition.teambition&android_scheme=' ; private _tail = '' ; private _href : string ; constructor ( $scope ) { super ( $scope ) ; this . configUrl ( ) ; } openUniversalLink ( ) { if ( this . _isIPhone && parseInt ( this . _browserVersion ) === 8 ) { if ( ! this . _isWechat ) { setTimeout ( ( ) => { window . location . href = 'https://itunes.apple.com/cn/app/teambition/id656664814' ; } , 300 ) ; } else { this . $rootScope . showTip = true ; if ( ! this . $rootScope . $$phase ) { this . $rootScope . $digest ( ) ; } return null ; } } else if ( this . _isAndroid && ! this . _isWechat ) { setTimeout ( ( ) => { window . location . href = 'https://www.teambition.com/apps' ; } , 300 ) ; } window . location . href = this . _href ; } private configUrl ( ) { const browserVersion = navigator . userAgent . match ( /\b[0-9]+_[0-9]+(?:_[0-9]+)?\b/ ) ; this . _browserVersion = browserVersion ? browserVersion [ 0 ] . split ( '_' ) [ 0 ] : '' ; const id = this . $state . params [ '_id' ] ; const type = this . $state . params [ 'type' ] ; if ( ! type && this . $state . current . name . indexOf ( 'project' ) !== - 1 && id ) { this . _tail = `project:${ id }` ; } else if ( type && id ) { this . _tail = `${ type }:${ id }` ; } else if ( this . $state . current . name === 'subtask' ) { this . _tail = `subtask:${ id }` ; } else if ( this . $state . current . name === 'collections' ) { this . _tail = `collection:${ id }` ; } if ( this . _isAndroid ) { this . _android ( ) ; } else if ( this . _isIPhone ) { this . _ios ( ) ; } else if ( ! this . _isWechat ) { this . _href = this . _urlSchema + this . _tail ; } } private _android ( ) { if ( this . _isWechat ) { this . _href = `${ this . _androidSchema }${ encodeURIComponent ( this . _urlSchema + this . _tail ) }` ; } else { this . _href = this . _urlSchema + this . _tail ; } } private _ios ( ) { if ( parseInt ( this . _browserVersion ) >= 9 ) { this . _href = `${ this . _magicLink }${ this . _tail }` ; } else { this . _href = this . _urlSchema ; } } } angular . module ( 'teambition' ) . controller ( 'BannerView' , BannerView ) ;