Files
freeplanet/src/root/home/home.ts

294 lines
7.9 KiB
TypeScript
Raw Normal View History

import Vue from 'vue'
import { Component } from 'vue-property-decorator'
import { GlobalStore, UserStore } from '@store'
import { Logo } from '../../components/logo'
2019-03-13 13:40:17 +01:00
import VueScrollReveal from 'vue-scroll-reveal'
import { tools } from '@src/store/Modules/tools'
Vue.use(VueScrollReveal, {
class: 'v-scroll-reveal', // A CSS class applied to elements with the v-scroll-reveal directive; useful for animation overrides.
duration: 1200,
scale: 0.95,
distance: '10px',
rotate: {
x: 0,
y: 0,
z: 0
}
// mobile: true
2019-03-13 13:40:17 +01:00
})
@Component({
components: { Logo }
})
export default class Home extends Vue {
2019-03-13 13:40:17 +01:00
public text: string = ''
public visibile: boolean = false
public cardvisible: string = 'hidden'
public displaycard: string = 'block'
public svgclass: string = 'svgclass'
public $t: any
public firstClassSection: string = 'landing fade homep-cover-img animate-fade homep-cover-img-1'
2018-11-11 19:27:04 +01:00
public $q
2019-03-13 13:40:17 +01:00
public polling
2018-11-11 19:27:04 +01:00
constructor() {
super()
// console.log('Home constructor...')
this.initprompt()
}
2019-03-13 13:40:17 +01:00
public mounted() {
2019-03-08 02:04:56 +01:00
let primo = true
2019-03-13 13:40:17 +01:00
const mytime = 10000
2019-03-08 02:04:56 +01:00
this.polling = setInterval(() => {
this.firstClassSection = 'landing fade homep-cover-img ' + (primo ? 'homep-cover-img-2' : 'homep-cover-img-1')
primo = !primo
// console.log('this.firstClassSection', this.firstClassSection)
2019-03-08 02:04:56 +01:00
}, mytime)
}
2019-03-13 13:40:17 +01:00
public beforeDestroy() {
2019-03-08 02:04:56 +01:00
console.log('beforeDestroy')
clearInterval(this.polling)
}
2019-03-13 13:40:17 +01:00
public created() {
GlobalStore.actions.prova()
}
2019-03-08 02:04:56 +01:00
get isLogged() {
return UserStore.state.isLogged
}
2019-03-08 02:04:56 +01:00
get TelegramSupport() {
return process.env.TELEGRAM_SUPPORT
}
2019-03-13 13:40:17 +01:00
public meta() {
return {
keywords: { name: 'keywords', content: 'Quasar website' },
// meta tags
meta: {
mykey: { name: 'mykey', content: 'Key 1' },
description: { name: 'description', content: 'Page 1' },
keywords: { name: 'keywords', content: 'Quasar website' },
2019-03-13 13:40:17 +01:00
equiv: { 'http-equiv': 'Content-Type', 'content': 'text/html; charset=UTF-8' }
}
}
}
2019-03-13 13:40:17 +01:00
public mystilecard() {
return {
visibility: this.cardvisible,
display: this.displaycard
}
}
get conta() {
return GlobalStore.state.conta
}
2019-03-13 13:40:17 +01:00
public getenv(myvar) {
2019-03-08 02:04:56 +01:00
return process.env[myvar]
}
set conta(valore) {
GlobalStore.actions.setConta(valore)
2019-03-13 13:40:17 +01:00
const my = this.$q.lang.isoName
tools.showNotif(this.$q, String(my))
}
2019-03-13 13:40:17 +01:00
public initprompt() {
window.addEventListener('beforeinstallprompt', function(event) {
2019-02-13 18:48:30 +01:00
// console.log('******************************** beforeinstallprompt fired')
event.preventDefault()
// console.log('§§§§§§§§§§§§§§§§§§§§ IMPOSTA DEFERRED PROMPT !!!!!!!!!!!!!!!!! ')
// #Todo++ IMPOSTA DEFERRED PROMPT
return false
})
}
2019-03-13 13:40:17 +01:00
get isInCostruction() {
return process.env.IN_CONSTRUCTION === '1'
}
2019-03-13 13:40:17 +01:00
public getPermission() {
return Notification.permission
}
2019-03-13 13:40:17 +01:00
public NotServiceWorker() {
return (!('serviceWorker' in navigator))
}
2019-03-13 13:40:17 +01:00
public PagLogin() {
this.$router.replace('/signin')
}
2019-03-13 13:40:17 +01:00
public PagReg() {
this.$router.replace('/signup')
}
2019-03-13 13:40:17 +01:00
public displayConfirmNotification() {
let options = null
if ('serviceWorker' in navigator) {
options = {
body: 'You successfully subscribed to our Notification service!',
2019-02-05 03:39:56 +01:00
icon: '/statics/icons/app-icon-96x96.png',
image: '/statics/images/sf-boat.jpg',
dir: 'ltr',
2019-02-16 02:01:17 +01:00
lang: 'enUs', // BCP 47,
vibrate: [100, 50, 200],
2019-02-05 03:39:56 +01:00
badge: '/statics/icons/app-icon-96x96.png',
tag: 'confirm-notification',
renotify: true, // if it's already sent, will Vibrate anyway
actions: [
2019-02-05 03:39:56 +01:00
{ action: 'confirm', title: 'Okay', icon: '/statics/icons/app-icon-96x96.png' },
{ action: 'cancel', title: 'Cancel', icon: '/statics/icons/app-icon-96x96.png' }
]
}
if ('serviceWorker' in navigator) {
navigator.serviceWorker.ready
2019-03-13 13:40:17 +01:00
.then(function(swreg) {
swreg.showNotification('Successfully subscribed!', options)
})
}
}
}
2019-03-13 13:40:17 +01:00
public urlBase64ToUint8Array(base64String) {
const padding = '='.repeat((4 - base64String.length % 4) % 4)
const base64 = (base64String + padding)
2019-02-05 03:39:56 +01:00
.replace(/\-/g, '+')
.replace(/_/g, '/')
2019-02-05 03:39:56 +01:00
2019-03-13 13:40:17 +01:00
const rawData = window.atob(base64)
const outputArray = new Uint8Array(rawData.length)
2019-02-05 03:39:56 +01:00
for (let i = 0; i < rawData.length; ++i) {
outputArray[i] = rawData.charCodeAt(i)
2019-02-05 03:39:56 +01:00
}
return outputArray
2019-02-05 03:39:56 +01:00
}
2019-03-13 13:40:17 +01:00
public dataURItoBlob(dataURI) {
const byteString = atob(dataURI.split(',')[1])
const mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0]
const ab = new ArrayBuffer(byteString.length)
const ia = new Uint8Array(ab)
2019-02-05 03:39:56 +01:00
for (let i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i)
2019-02-05 03:39:56 +01:00
}
2019-03-13 13:40:17 +01:00
const blob = new Blob([ab], { type: mimeString })
return blob
2019-02-05 03:39:56 +01:00
}
2019-03-13 13:40:17 +01:00
public showNotificationExample() {
let options = null
2019-03-13 13:40:17 +01:00
const mythis = this
if ('serviceWorker' in navigator) {
options = {
body: mythis.$t('notification.subscribed'),
icon: '/statics/icons/android-chrome-192x192.png',
image: '/statics/images/freeplanet.png',
dir: 'ltr',
2019-02-16 02:01:17 +01:00
lang: 'enUs', // BCP 47,
vibrate: [100, 50, 200],
badge: '/statics/icons/android-chrome-192x192.png',
tag: 'confirm-notification',
renotify: true, // if it's already sent, will Vibrate anyway
actions: [
2019-03-08 02:04:56 +01:00
{ action: 'confirm', title: mythis.$t('dialog.ok'), icon: '/statics/icons/android-chrome-192x192.png' }
// { action: 'cancel', title: 'Cancel', icon: '/statics/icons/android-chrome-192x192.png', }
]
}
navigator.serviceWorker.ready
2019-03-13 13:40:17 +01:00
.then(function(swreg) {
swreg.showNotification('aaa', options)
})
}
}
2019-03-13 13:40:17 +01:00
public askfornotification() {
tools.showNotif(this.$q, this.$t('notification.waitingconfirm'), {color: 'positive', icon: 'notifications'})
2019-03-08 02:04:56 +01:00
Notification.requestPermission((result) => {
console.log('User Choice', result)
if (result === 'granted') {
2019-03-13 13:40:17 +01:00
tools.showNotif(this.$q, this.$t('notification.confirmed'), {color: 'positive', icon: 'notifications'})
} else {
2019-03-13 13:40:17 +01:00
tools.showNotif(this.$q, this.$t('notification.denied'), {color: 'negative', icon: 'notifications'})
// displayConfirmNotification();
}
})
}
2019-03-13 13:40:17 +01:00
public test_fetch() {
fetch('https:/httpbin.org/post', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
// mode: 'no-cors',
mode: 'cors',
body: JSON.stringify({ message: 'Does this work?' })
2019-03-13 13:40:17 +01:00
}).then(function(response) {
console.log(response)
2019-03-13 13:40:17 +01:00
if (response) {
return response.json()
2019-03-13 13:40:17 +01:00
}
else {
return null
2019-03-13 13:40:17 +01:00
}
}).then(function(data) {
console.log(data)
2019-03-13 13:40:17 +01:00
}).catch(function(err) {
console.log(err)
})
}
2019-03-13 13:40:17 +01:00
public openCreatePostModal() {
console.log('APERTO ! openCreatePostModal')
this.conta = this.conta + 1
this.visibile = !this.visibile
if (this.visibile) {
this.displaycard = 'block'
this.cardvisible = 'visible'
} else {
this.displaycard = 'block'
this.cardvisible = 'hidden'
}
}
2019-03-08 02:04:56 +01:00
/*
backgroundSequence() {
window.clearTimeout()
let k = 0
for (let i = 0; i < bgImageArray.length; i++) {
const mythis = this
setTimeout(function() {
document.documentElement.style.background = 'url(' + mythis.base + mythis.bgImageArray[k] + ') no-repeat center center fixed'
document.documentElement.style.backgroundSize = 'cover'
if ((k + 1) === mythis.bgImageArray.length) { setTimeout(function() { mythis.backgroundSequence() }, (mythis.secs * 1000))} else { k++ }
}, (mythis.secs * 1000) * i)
}
}
backgroundSequence()
*/
}