Skip to content

Commit

Permalink
[fix] bug export, improve perf panel
Browse files Browse the repository at this point in the history
  • Loading branch information
valentin-debris committed Dec 11, 2020
1 parent b384115 commit 51f9542
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 109 deletions.
24 changes: 18 additions & 6 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ export default class App extends Vue {
await this.synchro();
});
EventBus.$on("APP_SYNCHRONIZE_RUN", async () => {
await this.synchro();
});
EventBus.$on("SHOW_SNAKBAR", (mes: string, duration = 3000) => {
if (mes) {
this.messageSk = mes;
Expand Down Expand Up @@ -186,12 +190,20 @@ export default class App extends Vue {
];
await Promise.all(syncs).then((results) => {
console.log("[HP] Sync done");
this.messageSk = "Synchronisation terminée !";
this.durationSk = 2000;
EventBus.$emit("APP_SYNCHRONIZE_DONE");
const checker = results.every((v) => v === true);
if (checker == true) {
console.log("[HP] Sync done");
this.messageSk = "Synchronisation terminée !";
this.durationSk = 2000;
EventBus.$emit("APP_SYNCHRONIZE_DONE");
} else {
console.log("[HP] Sync failed");
this.messageSk =
"La synchronisation a échoué. Réessayez ou reconnectez-vous.";
this.durationSk = 10000;
}
});
}
Expand Down
1 change: 0 additions & 1 deletion src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,6 @@ if (!gotTheLock) {
// var link;
// // This will catch clicks on links such as <a href="foobar://abc=1">open in foobar</a>
// app.on("open-url", function(event, data) {
// console.log("aaaa");
// event.preventDefault();
// link = data;
// });
Expand Down
55 changes: 31 additions & 24 deletions src/components/App/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -205,32 +205,39 @@ export default class Header extends Vue {
start: "desc",
})
.exec()
.then((times) => {
.then(async (times) => {
this.lastTimes = [];
const filters: string[] = [];
times.forEach(async (i) => {
if (filters.includes(i.title + i.taskId)) {
return;
}
filters.push(i.title + i.taskId);
let title = i.title;
const tk = await i.taskId_;
const cl = await (await tk?.projectId_)?.clientId_;
if (cl) {
if (tk!.title) title += " | " + tk!.title;
else title += " | " + tk!.refPropal;
title += " | " + cl.title;
} else {
title += " | Perso";
}
this.lastTimes.push({
id: i.id,
type: "time",
title: title,
obj: i,
});
const items = await Promise.all(
times.map(async (i) => {
if (filters.includes(i.title + i.taskId)) {
return;
}
filters.push(i.title + i.taskId);
let title = i.title;
const tk = await i.taskId_;
const cl = await (await tk?.projectId_)?.clientId_;
if (cl) {
if (tk!.title) title += " | " + tk!.title;
else title += " | " + tk!.refPropal;
title += " | " + cl.title;
} else {
title += " | Perso";
}
return {
id: i.id,
type: "time",
title: title,
obj: i,
};
})
);
//@ts-ignore
this.lastTimes = items.filter(function(el: CustomItem) {
return el != null;
});
});
}
Expand Down
1 change: 1 addition & 0 deletions src/components/App/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export default class Login extends Vue {
if (connected) {
this.dialog = false;
EventBus.$emit("APP_SYNCHRONIZE_RUN");
} else {
this.alert = true;
}
Expand Down
83 changes: 45 additions & 38 deletions src/components/App/Panel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
v-click-outside="clickOutsidePanel"
>
<div class="infoTime" v-if="time">
<v-row class="timeTitle">
<v-row class="timeTitle" v-click-outside="onFocusDesc">
<v-text-field
label="Description"
v-model="description"
@focus="onFocusDesc"
@blur="onFocusDesc"
></v-text-field>

<v-data-table
Expand Down Expand Up @@ -243,22 +242,21 @@ export default class Panel extends Vue {
private subTk: Subscription | null = null;
private subTs: Subscription | null = null;
public clickOutsidePanel() {
public clickOutsidePanel(e: MouseEvent) {
if (this.setupDone == false || !this.time) return;
let ignore = false;
//@ts-ignore
e?.path?.forEach((p) => {
if (p?.classList?.contains("v-menu__content")) ignore = true;
});
if (ignore) return;
this.time = null;
}
public onFocusDesc(e: FocusEvent) {
public onFocusDesc(e: FocusEvent | MouseEvent) {
if (e.type == "focus") this.openLastTimes = true;
else {
//use a delay to allow the "onSelectlastT" to works
setTimeout(
function() {
//@ts-ignore
this.openLastTimes = false;
}.bind(this),
500
);
}
else this.openLastTimes = false;
}
public async onSelectLastT(i: CustomItem) {
Expand All @@ -277,6 +275,7 @@ export default class Panel extends Vue {
await this.setupSelects();
this.setupDone = true;
}
this.openLastTimes = false;
}
public async onChangeAll(item: CustomItem) {
Expand Down Expand Up @@ -467,32 +466,39 @@ export default class Panel extends Vue {
start: "desc",
})
.exec()
.then((times) => {
.then(async (times) => {
this.lastTimes = [];
const filters: string[] = [];
times.forEach(async (i) => {
if (filters.includes(i.title + i.taskId)) {
return;
}
filters.push(i.title + i.taskId);
let title = i.title;
const tk = await i.taskId_;
const cl = await (await tk?.projectId_)?.clientId_;
if (cl) {
if (tk!.title) title += " | " + tk!.title;
else title += " | " + tk!.refPropal;
title += " | " + cl.title;
} else {
title += " | Perso";
}
this.lastTimes.push({
id: i.id,
type: "time",
title: title,
obj: i,
});
const items = await Promise.all(
times.map(async (i) => {
if (filters.includes(i.title + i.taskId)) {
return;
}
filters.push(i.title + i.taskId);
let title = i.title;
const tk = await i.taskId_;
const cl = await (await tk?.projectId_)?.clientId_;
if (cl) {
if (tk!.title) title += " | " + tk!.title;
else title += " | " + tk!.refPropal;
title += " | " + cl.title;
} else {
title += " | Perso";
}
return {
id: i.id,
type: "time",
title: title,
obj: i,
};
})
);
//@ts-ignore
this.lastTimes = items.filter(function(el: CustomItem) {
return el != null;
});
});
}
Expand Down Expand Up @@ -722,6 +728,7 @@ export default class Panel extends Vue {
right: 0;
bottom: 20px;
transform: translateY(100%);
cursor: pointer;
::v-deep {
.v-data-table__mobile-row {
Expand Down
8 changes: 7 additions & 1 deletion src/components/TimeListDay/TimeItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ export default class TimeItem extends Vue {
}
public togglePan() {
EventBus.$emit("TOGGLE_PAN", this.time);
setTimeout(
function() {
//@ts-ignore
EventBus.$emit("TOGGLE_PAN", this.time);
}.bind(this),
200
);
}
public async startTimeFromHere() {
Expand Down
4 changes: 4 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ if (getIntegrations && getIntegrations().browser) {

Vue.directive("click-outside", {
bind() {
//@ts-ignore
if (!this) return;
//@ts-ignore
this.event = (event) => this.vm.$emit(this.expression, event); //@ts-ignore
this.el.addEventListener("click", this.stopProp); //@ts-ignore
document.body.addEventListener("click", this.event);
},
unbind() {
//@ts-ignore
if (!this) return;
//@ts-ignore
this.el.removeEventListener("click", this.stopProp); //@ts-ignore
document.body.removeEventListener("click", this.event);
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import taskSchema from "@/schemas/Task.schema";
import timeSchema from "@/schemas/Time.schema";
import { v4 as uuidv4 } from "uuid";

const isDev = process.env.NODE_ENV !== "production";

if (process.env.NODE_ENV === "development") {
// in dev-mode we add the dev-mode plugin
// which does many checks and adds full error messages
Expand Down
45 changes: 24 additions & 21 deletions src/plugins/dolibarr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import keytar from "keytar";
require("dotenv").config();

const isDev = process.env.NODE_ENV !== "production";
const keytarService = isDev ? "maginaTimerDev" : "maginaTimer";
const keytarService = isDev ? "maginaTimerDev" : "maginaTimerProd";

axios.defaults.baseURL = process.env.VUE_APP_DOLIBARR_HOST + "/api/index.php/";
async function checkCred() {
Expand Down Expand Up @@ -71,26 +71,28 @@ async function getData(type: string, collection: RxCollection, urlApi: string) {
//First import
await collection.bulkInsert(response.data);
} else {
await response.data.forEach(async (i: RxTimeDocument) => {
if (type == "times") {
//When sync items, it returns also the ones that we have created between
// the last sync & now, so get the right ID to avoid duplicate
const dupli = await collection
.findOne({
selector: {
dolibarrId: i.dolibarrId,
},
})
.exec();
if (dupli) {
i.id = dupli.id;
} else if (!i.id) {
//The upsert doesn't trigger the "preInsert", used for times
i.id = DatabaseService.getRandomId();
await Promise.all(
response.data.map(async (i: RxTimeDocument) => {
if (type == "times") {
//When sync items, it returns also the ones that we have created between
// the last sync & now, so get the right ID to avoid duplicate
const dupli = await collection
.findOne({
selector: {
dolibarrId: i.dolibarrId,
},
})
.exec();
if (dupli) {
i.id = dupli.id;
} else if (!i.id) {
//The upsert doesn't trigger the "preInsert", used for times
i.id = DatabaseService.getRandomId();
}
}
}
await collection.upsert(i);
});
await collection.upsert(i);
})
);
}
}

Expand Down Expand Up @@ -260,7 +262,8 @@ async function updateDolibarr(time: RxTimeDocument) {
const success = await removeTime(time);
if (success) {
const db = await DatabaseService.get();
await db.times.insert(obj); //The insert will be trigger by this listener and the time will be pushed
const newT = await db.times.insert(obj); //The insert will be trigger by this listener and the time will be pushed
await createTime(newT);
}
} else {
await updateTime(time);
Expand Down
19 changes: 9 additions & 10 deletions src/plugins/errorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@ let sentryInit = false;
const isDev = process.env.NODE_ENV !== "production";

function init() {
Sentry.init({
dsn:
process.env.VUE_APP_CRASH_HOST
});
sentryInit = true;
Sentry.init({
dsn: process.env.VUE_APP_CRASH_HOST,
});
sentryInit = true;
}

/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
function sendException(err: any) {
if (isDev) console.log({ err });
if (sentryInit === false) {
init();
}
Sentry.captureException(err);
if (isDev) console.log({ err });
if (sentryInit === false) {
init();
}
Sentry.captureException(err);
}

export default sendException;
Loading

0 comments on commit 51f9542

Please sign in to comment.