fix swipe down & up

This commit is contained in:
Paolo Possanzini
2018-01-16 12:54:08 +01:00
parent dfcd8ed03c
commit 258f275de3
8 changed files with 52 additions and 23 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
+5 -5
View File
File diff suppressed because one or more lines are too long
+8 -2
View File
@@ -137,8 +137,14 @@ export default {
callHub: function() {
this.hub.Hello();
},
toggleMainView() {
appModelActions.MainViewToggle(this.$store);
toggleMainView(direction) {
if(!direction || direction == 'down')
appModelActions.MainViewToggle(this.$store);
else
{
this.applyViewPosition(-window.innerHeight + 84);
}
},
movepanel(e) {
if (e && e.touches && e.touches[0]) {
@@ -38,6 +38,7 @@ export function to(promise) {
.catch(err => err.response);
}
export class baseRestService {
public errorsToShow: number[] = [404, 500];
+16 -7
View File
@@ -10,7 +10,7 @@ function swipedetect(el, callback, onmovecallback) {
distX,
distY,
threshold = 10, //required min distance traveled to be considered swipe
restraint = 100, // maximum distance allowed at the same time in perpendicular direction
restraint = 1000, // maximum distance allowed at the same time in perpendicular direction
allowedTime = 300, // maximum time allowed to travel that distance
elapsedTime,
startTime,
@@ -30,6 +30,15 @@ function swipedetect(el, callback, onmovecallback) {
touchsurface.addEventListener('touchmove', function(e) {
e.preventDefault() // prevent scrolling when inside DIV
var touchobj = e.changedTouches[0];
if (Math.abs(distX) >= threshold && Math.abs(distY) <= restraint) { // 2nd condition for horizontal swipe met
swipedir = (distX < 0) ? 'left' : 'right' // if dist traveled is negative, it indicates left swipe
startX = touchobj.pageX
} else if (Math.abs(distY) >= threshold && Math.abs(distX) <= restraint) { // 2nd condition for vertical swipe met
swipedir = (distY < 0) ? 'up' : 'down' // if dist traveled is negative, it indicates up swipe
startY = touchobj.pageY
}
if (onmovecallback)
onmovecallback(e)
@@ -40,13 +49,13 @@ function swipedetect(el, callback, onmovecallback) {
distX = touchobj.pageX - startX // get horizontal dist traveled by finger while in contact with surface
distY = touchobj.pageY - startY // get vertical dist traveled by finger while in contact with surface
elapsedTime = new Date().getTime() - startTime // get time elapsed
if (elapsedTime <= allowedTime) { // first condition for awipe met
if (Math.abs(distX) >= threshold && Math.abs(distY) <= restraint) { // 2nd condition for horizontal swipe met
swipedir = (distX < 0) ? 'left' : 'right' // if dist traveled is negative, it indicates left swipe
} else if (Math.abs(distY) >= threshold && Math.abs(distX) <= restraint) { // 2nd condition for vertical swipe met
swipedir = (distY < 0) ? 'up' : 'down' // if dist traveled is negative, it indicates up swipe
}
if (Math.abs(distX) >= threshold && Math.abs(distY) <= restraint) { // 2nd condition for horizontal swipe met
swipedir = (distX < 0) ? 'left' : 'right' // if dist traveled is negative, it indicates left swipe
} else if (Math.abs(distY) >= threshold && Math.abs(distX) <= restraint) { // 2nd condition for vertical swipe met
swipedir = (distY < 0) ? 'up' : 'down' // if dist traveled is negative, it indicates up swipe
}
handleswipe(swipedir)
e.preventDefault()
}, false)
+14
View File
@@ -1,4 +1,18 @@
import Factory from "./factoryService";
import { MessageService } from "./messageService";
export function awaiter(promise) {
Factory.Get(MessageService).publishToChannel("show-loading");
return promise.then(data => {
Factory.Get(MessageService).publishToChannel("hide-loading");
return data
})
.catch(err => {
Factory.Get(MessageService).publishToChannel("hide-loading");
return err;
});
}
export { Factory, MessageService };
+5 -3
View File
@@ -2,9 +2,6 @@
import { LoginService } from "./services/loginService";
import { LocalizationService } from "./services/localizationService";
// Page and modules
import Header from "./modules/app-header.vue";
import Footer from "./modules/app-footer.vue";
@@ -14,6 +11,11 @@ import UserInfoDialog from "./modules/user-info-dialog.vue";
import MachineInfoDialog from "./modules/machine-info-dialog.vue";
import AxesCalibration from "./modules/axes-calibration-dialog.vue";
export {
LoginService,
LocalizationService,
+2 -5
View File
@@ -2,7 +2,7 @@ import Vue from "vue";
import Component from "vue-class-component";
import { Modal, ModalHelper } from "./base-components"
import { Factory, MessageService } from "src/_base";
import { Factory, MessageService, awaiter } from "src/_base";
import { LoginService } from "src/app.modules";
@@ -15,13 +15,10 @@ export default class Login extends Vue {
async doLogin() {
var service = Factory.Get(LoginService);
Factory.Get(MessageService).publishToChannel("show-loading");
if (await service.doLogin(this.user)) {
if (await awaiter(service.doLogin(this.user))) {
ModalHelper.HideModal();
}
Factory.Get(MessageService).publishToChannel("hide-loading");
this.hasError = !service.isAuthenticated;
}
}