mirror of
https://github.com/frappe/books.git
synced 2024-11-09 23:30:56 +00:00
Merge pull request #675 from frappe/revise-telemetry
fix: review telemetry
This commit is contained in:
commit
fe3b8c4c16
@ -1,5 +1,6 @@
|
||||
import { Fyo } from 'fyo';
|
||||
import { Noun, Telemetry, Verb } from './types';
|
||||
import { ModelNameEnum } from 'models/types';
|
||||
|
||||
/**
|
||||
* # Telemetry
|
||||
@ -26,6 +27,11 @@ import { Noun, Telemetry, Verb } from './types';
|
||||
* the app is hidden.
|
||||
*/
|
||||
|
||||
const ignoreList: string[] = [
|
||||
ModelNameEnum.AccountingLedgerEntry,
|
||||
ModelNameEnum.StockLedgerEntry,
|
||||
];
|
||||
|
||||
export class TelemetryManager {
|
||||
#url = '';
|
||||
#token = '';
|
||||
@ -80,7 +86,11 @@ export class TelemetryManager {
|
||||
}
|
||||
|
||||
#sendBeacon(verb: Verb, noun: Noun, more?: Record<string, unknown>) {
|
||||
if (!this.hasCreds || this.fyo.store.skipTelemetryLogging) {
|
||||
if (
|
||||
!this.hasCreds ||
|
||||
this.fyo.store.skipTelemetryLogging ||
|
||||
ignoreList.includes(noun)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -3,12 +3,15 @@ export type UniqueId = string;
|
||||
export type Timestamp = string;
|
||||
|
||||
export enum Verb {
|
||||
Started = 'started',
|
||||
Completed = 'completed',
|
||||
Created = 'created',
|
||||
Deleted = 'deleted',
|
||||
Submitted = 'submitted',
|
||||
Cancelled = 'cancelled',
|
||||
Imported = 'imported',
|
||||
Exported = 'exported',
|
||||
Printed = 'printed',
|
||||
Closed = 'closed',
|
||||
Opened = 'opened',
|
||||
Resumed = 'resumed',
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { emitMainProcessError } from 'backend/helpers';
|
||||
import { App, BrowserWindow } from 'electron';
|
||||
import fs from 'fs/promises';
|
||||
import path from 'path';
|
||||
@ -31,29 +30,11 @@ export async function saveHtmlAsPdf(
|
||||
printSelectionOnly: false,
|
||||
};
|
||||
|
||||
/**
|
||||
* After the printWindow content is ready, save as pdf and
|
||||
* then close the window and delete the temp html file.
|
||||
*/
|
||||
return await new Promise((resolve) => {
|
||||
printWindow.webContents.once('did-finish-load', () => {
|
||||
printWindow.webContents
|
||||
.printToPDF(printOptions)
|
||||
.then((data) => {
|
||||
fs.writeFile(savePath, data)
|
||||
.then(() => {
|
||||
const data = await printWindow.webContents.printToPDF(printOptions);
|
||||
await fs.writeFile(savePath, data);
|
||||
printWindow.close();
|
||||
fs.unlink(htmlPath)
|
||||
.then(() => {
|
||||
resolve(true);
|
||||
})
|
||||
.catch((err) => emitMainProcessError(err));
|
||||
})
|
||||
.catch((err) => emitMainProcessError(err));
|
||||
})
|
||||
.catch((err) => emitMainProcessError(err));
|
||||
});
|
||||
});
|
||||
await fs.unlink(htmlPath);
|
||||
return true;
|
||||
}
|
||||
|
||||
async function getInitializedPrintWindow(
|
||||
|
@ -26,7 +26,7 @@
|
||||
<Int
|
||||
v-if="configFields.limit"
|
||||
:df="configFields.limit"
|
||||
:value="limit"
|
||||
:value="limit ?? undefined"
|
||||
:border="true"
|
||||
@change="(value: number) => (limit = value)"
|
||||
/>
|
||||
@ -104,6 +104,7 @@ import Check from './Controls/Check.vue';
|
||||
import Int from './Controls/Int.vue';
|
||||
import Select from './Controls/Select.vue';
|
||||
import FormHeader from './FormHeader.vue';
|
||||
import { Verb } from 'fyo/telemetry/types';
|
||||
|
||||
interface ExportWizardData {
|
||||
useListFilters: boolean;
|
||||
@ -165,13 +166,13 @@ export default defineComponent({
|
||||
fieldtype: 'Check',
|
||||
label: t`Use List Filters`,
|
||||
fieldname: 'useListFilters',
|
||||
},
|
||||
} as Field,
|
||||
limit: {
|
||||
placeholder: 'Limit number of rows',
|
||||
fieldtype: 'Int',
|
||||
label: t`Limit`,
|
||||
fieldname: 'limit',
|
||||
},
|
||||
} as Field,
|
||||
exportFormat: {
|
||||
fieldtype: 'Select',
|
||||
label: t`Export Format`,
|
||||
@ -180,7 +181,7 @@ export default defineComponent({
|
||||
{ value: 'json', label: 'JSON' },
|
||||
{ value: 'csv', label: 'CSV' },
|
||||
],
|
||||
},
|
||||
} as Field,
|
||||
};
|
||||
},
|
||||
},
|
||||
@ -257,6 +258,9 @@ export default defineComponent({
|
||||
}
|
||||
|
||||
await saveData(data, filePath);
|
||||
this.fyo.telemetry.log(Verb.Exported, this.schemaName, {
|
||||
extension: this.exportFormat,
|
||||
});
|
||||
showExportInFolder(fyo.t`Export Successful`, filePath);
|
||||
},
|
||||
getFileName() {
|
||||
|
@ -216,6 +216,7 @@
|
||||
<script lang="ts">
|
||||
import { setupDummyInstance } from 'dummy';
|
||||
import { t } from 'fyo';
|
||||
import { Verb } from 'fyo/telemetry/types';
|
||||
import { DateTime } from 'luxon';
|
||||
import Button from 'src/components/Button.vue';
|
||||
import LanguageSelector from 'src/components/Controls/LanguageSelector.vue';
|
||||
@ -334,7 +335,7 @@ export default defineComponent({
|
||||
updateConfigFiles(fyo);
|
||||
await fyo.purgeCache();
|
||||
await this.setFiles();
|
||||
|
||||
this.fyo.telemetry.log(Verb.Created, 'dummy-instance');
|
||||
this.creatingDemo = false;
|
||||
},
|
||||
async setFiles() {
|
||||
|
@ -371,6 +371,7 @@
|
||||
<script lang="ts">
|
||||
import { DocValue } from 'fyo/core/types';
|
||||
import { Action } from 'fyo/model/types';
|
||||
import { Verb } from 'fyo/telemetry/types';
|
||||
import { ValidationError } from 'fyo/utils/errors';
|
||||
import { ModelNameEnum } from 'models/types';
|
||||
import { OptionField, RawValue, SelectOption } from 'schemas/types';
|
||||
@ -864,6 +865,7 @@ export default defineComponent({
|
||||
}
|
||||
}
|
||||
|
||||
this.fyo.telemetry.log(Verb.Imported, this.importer.schemaName);
|
||||
this.isMakingEntries = false;
|
||||
this.complete = true;
|
||||
},
|
||||
|
@ -34,6 +34,7 @@
|
||||
<PrintContainer
|
||||
v-if="printProps"
|
||||
ref="printContainer"
|
||||
:print-schema-name="schemaName"
|
||||
:template="printProps.template"
|
||||
:values="printProps.values"
|
||||
:scale="scale"
|
||||
@ -55,11 +56,11 @@ import PageHeader from 'src/components/PageHeader.vue';
|
||||
import { handleErrorWithDialog } from 'src/errorHandling';
|
||||
import { fyo } from 'src/initFyo';
|
||||
import { getPrintTemplatePropValues } from 'src/utils/printTemplates';
|
||||
import { showSidebar } from 'src/utils/refs';
|
||||
import { PrintValues } from 'src/utils/types';
|
||||
import { getFormRoute, openSettings, routeTo } from 'src/utils/ui';
|
||||
import { defineComponent } from 'vue';
|
||||
import PrintContainer from '../TemplateBuilder/PrintContainer.vue';
|
||||
import { showSidebar } from 'src/utils/refs';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'PrintView',
|
||||
@ -244,16 +245,16 @@ export default defineComponent({
|
||||
|
||||
this.templateList = list.map(({ name }) => name);
|
||||
},
|
||||
savePDF() {
|
||||
async savePDF() {
|
||||
const printContainer = this.$refs.printContainer as {
|
||||
savePDF: (name?: string) => void;
|
||||
savePDF: (name?: string) => Promise<void>;
|
||||
};
|
||||
|
||||
if (!printContainer?.savePDF) {
|
||||
return;
|
||||
}
|
||||
|
||||
printContainer.savePDF(this.doc?.name);
|
||||
await printContainer.savePDF(this.doc?.name);
|
||||
},
|
||||
async setTemplateFromDefault() {
|
||||
const defaultName =
|
||||
|
@ -145,20 +145,21 @@
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { Verb } from 'fyo/telemetry/types';
|
||||
import { Report } from 'reports/Report';
|
||||
import { reports } from 'reports/index';
|
||||
import { OptionField } from 'schemas/types';
|
||||
import Button from 'src/components/Button.vue';
|
||||
import Check from 'src/components/Controls/Check.vue';
|
||||
import Int from 'src/components/Controls/Int.vue';
|
||||
import Select from 'src/components/Controls/Select.vue';
|
||||
import PageHeader from 'src/components/PageHeader.vue';
|
||||
import { getReport } from 'src/utils/misc';
|
||||
import { getPathAndMakePDF } from 'src/utils/printTemplates';
|
||||
import { showSidebar } from 'src/utils/refs';
|
||||
import { paperSizeMap, printSizes } from 'src/utils/ui';
|
||||
import { PropType, defineComponent } from 'vue';
|
||||
import ScaledContainer from '../TemplateBuilder/ScaledContainer.vue';
|
||||
import { getPathAndMakePDF } from 'src/utils/printTemplates';
|
||||
import { OptionField } from 'schemas/types';
|
||||
import { paperSizeMap, printSizes } from 'src/utils/ui';
|
||||
import Select from 'src/components/Controls/Select.vue';
|
||||
import { showSidebar } from 'src/utils/refs';
|
||||
|
||||
export default defineComponent({
|
||||
components: { PageHeader, Button, Check, Int, ScaledContainer, Select },
|
||||
@ -276,6 +277,8 @@ export default defineComponent({
|
||||
this.size.width,
|
||||
this.size.height
|
||||
);
|
||||
|
||||
this.fyo.telemetry.log(Verb.Printed, this.report!.reportName);
|
||||
},
|
||||
cellClasses(cIdx: number, rIdx: number): string[] {
|
||||
const classes: string[] = [];
|
||||
|
@ -47,7 +47,7 @@
|
||||
<p v-if="loading" class="text-base text-gray-600">
|
||||
{{ t`Loading instance...` }}
|
||||
</p>
|
||||
<Button v-if="!loading" class="w-24" @click="$emit('setup-canceled')">{{
|
||||
<Button v-if="!loading" class="w-24" @click="cancel">{{
|
||||
t`Cancel`
|
||||
}}</Button>
|
||||
<Button
|
||||
@ -72,6 +72,8 @@
|
||||
<script lang="ts">
|
||||
import { DocValue } from 'fyo/core/types';
|
||||
import { Doc } from 'fyo/model/doc';
|
||||
import { Verb } from 'fyo/telemetry/types';
|
||||
import { ModelNameEnum } from 'models/types';
|
||||
import { Field } from 'schemas/types';
|
||||
import Button from 'src/components/Button.vue';
|
||||
import FormContainer from 'src/components/FormContainer.vue';
|
||||
@ -153,6 +155,7 @@ export default defineComponent({
|
||||
// @ts-ignore
|
||||
window.sw = this;
|
||||
}
|
||||
this.fyo.telemetry.log(Verb.Started, ModelNameEnum.SetupWizard);
|
||||
},
|
||||
methods: {
|
||||
async fill() {
|
||||
@ -198,8 +201,13 @@ export default defineComponent({
|
||||
}
|
||||
|
||||
this.loading = true;
|
||||
this.fyo.telemetry.log(Verb.Completed, ModelNameEnum.SetupWizard);
|
||||
this.$emit('setup-complete', this.doc.getValidDict());
|
||||
},
|
||||
cancel() {
|
||||
this.fyo.telemetry.log(Verb.Cancelled, ModelNameEnum.SetupWizard);
|
||||
this.$emit('setup-canceled');
|
||||
},
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
@ -49,6 +49,7 @@ import {
|
||||
generateCodeFrame,
|
||||
SourceLocation,
|
||||
} from '@vue/compiler-dom';
|
||||
import { Verb } from 'fyo/telemetry/types';
|
||||
import ErrorBoundary from 'src/components/ErrorBoundary.vue';
|
||||
import { getPathAndMakePDF } from 'src/utils/printTemplates';
|
||||
import { PrintValues } from 'src/utils/types';
|
||||
@ -66,6 +67,7 @@ export default defineComponent({
|
||||
components: { ScaledContainer, ErrorBoundary },
|
||||
props: {
|
||||
template: { type: String, required: true },
|
||||
printSchemaName: { type: String, required: true },
|
||||
scale: { type: Number, default: 0.65 },
|
||||
width: { type: Number, default: 21 },
|
||||
height: { type: Number, default: 29.7 },
|
||||
@ -179,6 +181,8 @@ export default defineComponent({
|
||||
this.width,
|
||||
this.height
|
||||
);
|
||||
|
||||
this.fyo.telemetry.log(Verb.Printed, this.printSchemaName);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
@ -46,6 +46,7 @@
|
||||
<div v-if="canDisplayPreview" class="p-4 overflow-auto custom-scroll">
|
||||
<PrintContainer
|
||||
ref="printContainer"
|
||||
:print-schema-name="displayDoc!.schemaName"
|
||||
:template="doc.template!"
|
||||
:values="values!"
|
||||
:scale="scale"
|
||||
|
@ -290,6 +290,8 @@ export async function updatePrintTemplates(fyo: Fyo) {
|
||||
updateList.push(...updates);
|
||||
}
|
||||
|
||||
const isLogging = fyo.store.skipTelemetryLogging;
|
||||
fyo.store.skipTelemetryLogging = true;
|
||||
for (const { name, type, template } of updateList) {
|
||||
const doc = await getDocFromNameIfExistsElseNew(
|
||||
ModelNameEnum.PrintTemplate,
|
||||
@ -299,6 +301,7 @@ export async function updatePrintTemplates(fyo: Fyo) {
|
||||
await doc.set({ name, type, template, isCustom: false });
|
||||
await doc.sync();
|
||||
}
|
||||
fyo.store.skipTelemetryLogging = isLogging;
|
||||
}
|
||||
|
||||
function getPrintTemplateUpdateList(
|
||||
|
Loading…
Reference in New Issue
Block a user