@tech4good/angular-schematics 13.2.0 → 13.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/collection.json +6 -0
- package/src/container/files/__name@dasherize__/+state/__name@dasherize__.actions.ts.template +2 -4
- package/src/container/files/__name@dasherize__/+state/__name@dasherize__.effects.ts.template +1 -1
- package/src/container/files/__name@dasherize__/__name@dasherize__.component.ts.template +2 -4
- package/src/entity-in-example/files/__name@dasherize__/__name@dasherize__.actions.ts.template +270 -0
- package/src/entity-in-example/files/__name@dasherize__/__name@dasherize__.effects.ts.template +131 -0
- package/src/entity-in-example/files/__name@dasherize__/__name@dasherize__.model.ts.template +3 -0
- package/src/entity-in-example/files/__name@dasherize__/__name@dasherize__.reducer.spec.ts.template +13 -0
- package/src/entity-in-example/files/__name@dasherize__/__name@dasherize__.reducer.ts.template +51 -0
- package/src/entity-in-example/files/__name@dasherize__/__name@dasherize__.service.ts.template +50 -0
- package/src/entity-in-example/index.d.ts +2 -0
- package/src/entity-in-example/index.js +141 -0
- package/src/entity-in-example/index.js.map +1 -0
- package/src/entity-in-example/index_spec.d.ts +1 -0
- package/src/entity-in-example/index_spec.js +23 -0
- package/src/entity-in-example/index_spec.js.map +1 -0
- package/src/entity-in-example/schema.json +42 -0
- package/src/init/files/src/app/app-routing.module.ts.template +19 -0
- package/src/init/files/src/app/{app.component.html → app.component.html.template} +0 -0
- package/src/init/files/src/app/{app.component.scss → app.component.scss.template} +0 -0
- package/src/init/files/src/app/app.component.ts.template +41 -0
- package/src/init/files/src/app/app.module.ts.template +34 -0
- package/src/init/files/src/app/core/analytics/log.service.ts.template +35 -0
- package/src/init/files/src/app/core/analytics/time-analytics.service.ts.template +223 -0
- package/src/init/files/src/app/core/core.module.ts.template +71 -0
- package/src/init/files/src/app/core/firebase/firebase.service.ts.template +284 -0
- package/src/init/files/src/app/core/router/routing-state.service.ts.template +28 -0
- package/src/init/files/src/app/core/setup/firebase-setup.ts.template +25 -0
- package/src/init/files/src/app/core/setup/module-import-guard.ts.template +5 -0
- package/src/init/files/src/app/core/snackbar/snackbar.actions.ts.template +24 -0
- package/src/init/files/src/app/core/snackbar/snackbar.effects.ts.template +41 -0
- package/src/init/files/src/app/core/store/app.actions.ts.template +92 -0
- package/src/init/files/src/app/core/store/app.effects.ts.template +167 -0
- package/src/init/files/src/app/core/store/app.reducer.ts.template +30 -0
- package/src/init/files/src/app/core/store/app.selectors.ts.template +30 -0
- package/src/init/files/src/app/core/store/auth/auth.actions.ts.template +75 -0
- package/src/init/files/src/app/core/store/auth/auth.effects.ts.template +164 -0
- package/src/init/files/src/app/core/store/auth/auth.reducer.spec.ts.template +13 -0
- package/src/init/files/src/app/core/store/auth/auth.reducer.ts.template +26 -0
- package/src/init/files/src/app/core/store/auth/auth.selectors.ts.template +21 -0
- package/src/init/files/src/app/core/store/cached-load-connections.service.ts.template +404 -0
- package/src/init/files/src/app/core/store/cached-selectors.service.ts.template +376 -0
- package/src/init/files/src/app/core/store/effects.helpers.ts.template +66 -0
- package/src/init/files/src/app/core/store/user/user.actions.ts.template +269 -0
- package/src/init/files/src/app/core/store/user/user.effects.ts.template +131 -0
- package/src/init/files/src/app/core/store/user/user.model.ts.template +15 -0
- package/src/init/files/src/app/core/store/user/user.reducer.spec.ts.template +13 -0
- package/src/init/files/src/app/core/store/user/user.reducer.ts.template +50 -0
- package/src/init/files/src/app/core/store/user/user.service.ts.template +50 -0
- package/src/init/files/src/app/core/utils/string-case.utils.ts.template +96 -0
- package/src/init/files/src/app/general/e404/{e404.component.html → e404.component.html.template} +0 -0
- package/src/init/files/src/app/general/e404/{e404.component.scss → e404.component.scss.template} +0 -0
- package/src/init/files/src/app/general/e404/e404.component.spec.ts.template +25 -0
- package/src/init/files/src/app/general/e404/e404.component.ts.template +28 -0
- package/src/init/files/src/app/general/general-routing.module.ts.template +21 -0
- package/src/init/files/src/app/general/general.module.spec.ts.template +13 -0
- package/src/init/files/src/app/general/general.module.ts.template +30 -0
- package/src/init/files/src/app/general/login/{login.component.html → login.component.html.template} +0 -0
- package/src/init/files/src/app/general/login/{login.component.scss → login.component.scss.template} +0 -0
- package/src/init/files/src/app/general/login/login.component.spec.ts.template +25 -0
- package/src/init/files/src/app/general/login/login.component.ts.template +72 -0
- package/src/init/files/src/app/shared/shared.module.ts.template +81 -0
- package/src/init/files/src/environments/environment.prod.ts.template +5 -0
- package/src/init/files/src/environments/environment.ts.template +18 -0
- /package/src/init/files/src/styles/{_variables.scss → _variables.scss.template} +0 -0
- /package/src/init/files/src/{styles.scss → styles.scss.template} +0 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.entity = void 0;
|
|
13
|
+
const schematics_1 = require("@angular-devkit/schematics");
|
|
14
|
+
const change_1 = require("@schematics/angular/utility/change");
|
|
15
|
+
const find_module_1 = require("@schematics/angular/utility/find-module");
|
|
16
|
+
const parse_name_1 = require("@schematics/angular/utility/parse-name");
|
|
17
|
+
const workspace_1 = require("@schematics/angular/utility/workspace");
|
|
18
|
+
const core_1 = require("@angular-devkit/core");
|
|
19
|
+
const statements_adder_1 = require("../shared/statements-adder");
|
|
20
|
+
function addInserts(options) {
|
|
21
|
+
return (host, context) => {
|
|
22
|
+
const classifiedName = core_1.strings.classify(options.name);
|
|
23
|
+
const camelizedName = core_1.strings.camelize(options.name);
|
|
24
|
+
context.logger.info(`names: ${classifiedName}, ${camelizedName}`);
|
|
25
|
+
// Add core module changes
|
|
26
|
+
const coreModulePath = options.module;
|
|
27
|
+
const coreModuleText = (0, statements_adder_1.getSourceText)(host, coreModulePath);
|
|
28
|
+
context.logger.info(`modulePath: ${coreModulePath}`);
|
|
29
|
+
const entityEffectsPath = `/${options.path}/` +
|
|
30
|
+
core_1.strings.dasherize(options.name) + '/' +
|
|
31
|
+
core_1.strings.dasherize(options.name) + '.effects';
|
|
32
|
+
context.logger.info(`entityEffectsPath: ${entityEffectsPath}`);
|
|
33
|
+
const coreToEffectsPath = (0, find_module_1.buildRelativePath)(coreModulePath, entityEffectsPath);
|
|
34
|
+
context.logger.info(`coreToEffectsPath: ${coreToEffectsPath}`);
|
|
35
|
+
let insertChangesInCore = (0, statements_adder_1.simpleInsert)(coreModuleText, coreModulePath, [
|
|
36
|
+
'// Entity Effects',
|
|
37
|
+
'// Entity Effects'
|
|
38
|
+
], [
|
|
39
|
+
`import { ${classifiedName}Effects } from '${coreToEffectsPath}';`,
|
|
40
|
+
` ${classifiedName}Effects,`
|
|
41
|
+
]);
|
|
42
|
+
// Add app reducer changes
|
|
43
|
+
const appReducerPath = '//src/app/core/store/app.reducer.ts';
|
|
44
|
+
const appReducerText = (0, statements_adder_1.getSourceText)(host, appReducerPath);
|
|
45
|
+
context.logger.info(`appReducerPath: ${appReducerPath}`);
|
|
46
|
+
const entityReducerPath = `/${options.path}/` +
|
|
47
|
+
core_1.strings.dasherize(options.name) + '/' +
|
|
48
|
+
core_1.strings.dasherize(options.name) + '.reducer';
|
|
49
|
+
context.logger.info(`entityReducerPath: ${entityReducerPath}`);
|
|
50
|
+
const appToEntityReducerPath = (0, find_module_1.buildRelativePath)(appReducerPath, entityReducerPath);
|
|
51
|
+
let insertChangesInAppReducer = (0, statements_adder_1.simpleInsert)(appReducerText, appReducerPath, [
|
|
52
|
+
'// Entity Reducers',
|
|
53
|
+
'// Entity State',
|
|
54
|
+
'// Entity Reducers'
|
|
55
|
+
], [
|
|
56
|
+
`import * as from${classifiedName} from '${appToEntityReducerPath}';`,
|
|
57
|
+
` ${camelizedName}: from${classifiedName}.State;`,
|
|
58
|
+
` ${camelizedName}: from${classifiedName}.reducer,`
|
|
59
|
+
]);
|
|
60
|
+
// Add app selector changes
|
|
61
|
+
const appSelectorPath = '//src/app/core/store/app.selectors.ts';
|
|
62
|
+
const appSelectorText = (0, statements_adder_1.getSourceText)(host, appSelectorPath);
|
|
63
|
+
const entityServicePath = `/${options.path}/` +
|
|
64
|
+
core_1.strings.dasherize(options.name) + '/' +
|
|
65
|
+
core_1.strings.dasherize(options.name) + '.service';
|
|
66
|
+
const appToEntityServicePath = (0, find_module_1.buildRelativePath)(appSelectorPath, entityServicePath);
|
|
67
|
+
let insertChangesInAppSelector = (0, statements_adder_1.simpleInsert)(appSelectorText, appSelectorPath, [
|
|
68
|
+
'// Entity Selectors',
|
|
69
|
+
'// Entity Selectors',
|
|
70
|
+
'// Entity Selectors'
|
|
71
|
+
], [
|
|
72
|
+
`import { ${classifiedName}Service } from '${appToEntityServicePath}';`,
|
|
73
|
+
` private ${camelizedName}: ${classifiedName}Service,`,
|
|
74
|
+
` public get${classifiedName} = this.${camelizedName}.get${classifiedName};\n public get${classifiedName}s = this.${camelizedName}.get${classifiedName}s;\n public select${classifiedName} = this.${camelizedName}.select${classifiedName};\n public select${classifiedName}s = this.${camelizedName}.select${classifiedName}s;`
|
|
75
|
+
]);
|
|
76
|
+
// Add firebase service changes
|
|
77
|
+
const appFirebaseServicePath = '//src/app/core/firebase/firebase.service.ts';
|
|
78
|
+
const appFirebaseServiceText = (0, statements_adder_1.getSourceText)(host, appFirebaseServicePath);
|
|
79
|
+
const entityModelPath = `/${options.path}/` +
|
|
80
|
+
core_1.strings.dasherize(options.name) + '/' +
|
|
81
|
+
core_1.strings.dasherize(options.name) + '.model';
|
|
82
|
+
const appToEntityModelPath = (0, find_module_1.buildRelativePath)(appFirebaseServicePath, entityModelPath);
|
|
83
|
+
let insertChangesInFirebaseService = (0, statements_adder_1.simpleInsert)(appFirebaseServiceText, appFirebaseServicePath, [
|
|
84
|
+
'// Entity Models',
|
|
85
|
+
'// Entity Models'
|
|
86
|
+
], [
|
|
87
|
+
`import { ${classifiedName} } from '${appToEntityModelPath}';`,
|
|
88
|
+
` ${camelizedName}s: new BehaviorSubject<Array<{ type: string; result: ${classifiedName} }>>(
|
|
89
|
+
this.mockDBService.getInitialDBStateChanges('${camelizedName}s')
|
|
90
|
+
),`
|
|
91
|
+
]);
|
|
92
|
+
context.logger.info(`about to start committing`);
|
|
93
|
+
// For each of the files and corresponding set of changes, commit to the tree
|
|
94
|
+
[
|
|
95
|
+
[coreModulePath, insertChangesInCore],
|
|
96
|
+
[appReducerPath, insertChangesInAppReducer],
|
|
97
|
+
[appSelectorPath, insertChangesInAppSelector],
|
|
98
|
+
[appFirebaseServicePath, insertChangesInFirebaseService],
|
|
99
|
+
].map(([filePath, insertChanges]) => {
|
|
100
|
+
const declarationRecorder = host.beginUpdate(filePath);
|
|
101
|
+
for (const change of insertChanges) {
|
|
102
|
+
if (change instanceof change_1.InsertChange) {
|
|
103
|
+
declarationRecorder.insertLeft(change.pos, change.toAdd);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
host.commitUpdate(declarationRecorder);
|
|
107
|
+
});
|
|
108
|
+
return host;
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function entity(options) {
|
|
112
|
+
return (tree, context) => __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
// Make sure the command is executed in the directory where the component should be generated
|
|
114
|
+
if (!options.inDirectory) {
|
|
115
|
+
context.logger.info("Please navigate to the directory where you want to generate the entity.");
|
|
116
|
+
return (0, schematics_1.noop)();
|
|
117
|
+
}
|
|
118
|
+
const workspace = yield (0, workspace_1.getWorkspace)(tree);
|
|
119
|
+
const project = workspace.projects.get(options.project);
|
|
120
|
+
if (!project) {
|
|
121
|
+
throw new schematics_1.SchematicsException(`Project "${options.project}" does not exist.`);
|
|
122
|
+
}
|
|
123
|
+
if (options.path === undefined) {
|
|
124
|
+
options.path = (0, workspace_1.buildDefaultPath)(project);
|
|
125
|
+
}
|
|
126
|
+
options.module = (0, find_module_1.findModuleFromOptions)(tree, options);
|
|
127
|
+
const parsedPath = (0, parse_name_1.parseName)(options.path, options.name);
|
|
128
|
+
options.name = parsedPath.name;
|
|
129
|
+
options.path = parsedPath.path;
|
|
130
|
+
const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files'), [
|
|
131
|
+
(0, schematics_1.applyTemplates)(Object.assign(Object.assign({}, core_1.strings), options)),
|
|
132
|
+
(0, schematics_1.move)(parsedPath.path),
|
|
133
|
+
]);
|
|
134
|
+
return (0, schematics_1.chain)([
|
|
135
|
+
addInserts(options),
|
|
136
|
+
(0, schematics_1.mergeWith)(templateSource)
|
|
137
|
+
]);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
exports.entity = entity;
|
|
141
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2DAIoC;AAEpC,+DAA0E;AAC1E,yEAAmG;AACnG,uEAAmE;AACnE,qEAAuF;AACvF,+CAA+C;AAE/C,iEAAyE;AAEzE,SAAS,UAAU,CAAC,OAAY;IAC9B,OAAO,CAAC,IAAU,EAAE,OAAyB,EAAE,EAAE;QAE/C,MAAM,cAAc,GAAG,cAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACtD,MAAM,aAAa,GAAG,cAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACrD,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,cAAc,KAAK,aAA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YACX,UAAU,CAAC,OAAO,CAAC;YACnB,IAAA,sBAAS,EAAC,cAAc,CAAC;SAC1B,CAAC,CAAC;IACL,CAAC,CAAA,CAAC;AACJ,CAAC;AAvCD,wBAuCC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const schematics_1 = require("@angular-devkit/schematics");
|
|
13
|
+
const testing_1 = require("@angular-devkit/schematics/testing");
|
|
14
|
+
const path = require("path");
|
|
15
|
+
const collectionPath = path.join(__dirname, '../collection.json');
|
|
16
|
+
describe('entity', () => {
|
|
17
|
+
it('works', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
const runner = new testing_1.SchematicTestRunner('schematics', collectionPath);
|
|
19
|
+
const tree = yield runner.runSchematicAsync('entity', {}, schematics_1.Tree.empty()).toPromise();
|
|
20
|
+
expect(tree.files).toEqual([]);
|
|
21
|
+
}));
|
|
22
|
+
});
|
|
23
|
+
//# sourceMappingURL=index_spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index_spec.js","sourceRoot":"","sources":["index_spec.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,2DAAkD;AAClD,gEAAyE;AACzE,6BAA6B;AAG7B,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAAC;AAGlE,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;IACtB,EAAE,CAAC,OAAO,EAAE,GAAS,EAAE;QACrB,MAAM,MAAM,GAAG,IAAI,6BAAmB,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;QACrE,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,iBAAiB,CAAC,QAAQ,EAAE,EAAE,EAAE,iBAAI,CAAC,KAAK,EAAE,CAAC,CAAC,SAAS,EAAE,CAAC;QAEpF,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACjC,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"$id": "EntitySchema",
|
|
4
|
+
"title": "Entity Schema",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"description": "Creates a new entity in the default project.",
|
|
7
|
+
"properties": {
|
|
8
|
+
"index": {
|
|
9
|
+
"type": "number",
|
|
10
|
+
"default": 1
|
|
11
|
+
},
|
|
12
|
+
"path": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"format": "path",
|
|
15
|
+
"description": "The path at which to create the entity file, relative to the current workspace. Should typically be within /src/app/core/store.",
|
|
16
|
+
"visible": false
|
|
17
|
+
},
|
|
18
|
+
"project": {
|
|
19
|
+
"type": "string",
|
|
20
|
+
"description": "The name of the project.",
|
|
21
|
+
"$default": {
|
|
22
|
+
"$source": "projectName"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"name": {
|
|
26
|
+
"type": "string",
|
|
27
|
+
"description": "The name of the entity.",
|
|
28
|
+
"$default": {
|
|
29
|
+
"$source": "argv",
|
|
30
|
+
"index": 0
|
|
31
|
+
},
|
|
32
|
+
"x-prompt": "What name would you like to use for the entity?"
|
|
33
|
+
},
|
|
34
|
+
"inDirectory": {
|
|
35
|
+
"type": "boolean",
|
|
36
|
+
"x-prompt": "Are you currently in the directory where you want to generate the entity? (typically directly in src/app/core/store)"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"required": [
|
|
40
|
+
"name"
|
|
41
|
+
]
|
|
42
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { NgModule } from '@angular/core';
|
|
2
|
+
import { Routes, RouterModule } from '@angular/router';
|
|
3
|
+
|
|
4
|
+
// Containers
|
|
5
|
+
import { LoginComponent } from './general/login/login.component';
|
|
6
|
+
|
|
7
|
+
const appRoutes: Routes = [
|
|
8
|
+
// Replace when a default route is set up
|
|
9
|
+
{ path: '', redirectTo: 'login', pathMatch: 'full' },
|
|
10
|
+
{ path: '**', redirectTo: '404', pathMatch: 'full' },
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
@NgModule({
|
|
14
|
+
imports: [
|
|
15
|
+
RouterModule.forRoot(appRoutes, { useHash: true }),
|
|
16
|
+
],
|
|
17
|
+
exports: [RouterModule],
|
|
18
|
+
})
|
|
19
|
+
export class AppRoutingModule { }
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Component, OnInit } from '@angular/core';
|
|
2
|
+
import { Router, NavigationEnd } from '@angular/router';
|
|
3
|
+
import { select, Store } from '@ngrx/store';
|
|
4
|
+
import * as fromStore from './core/store/app.reducer';
|
|
5
|
+
import { LoadAuth } from './core/store/auth/auth.actions';
|
|
6
|
+
import { RoutingStateService } from './core/router/routing-state.service';
|
|
7
|
+
import { TimeAnalyticsService } from './core/analytics/time-analytics.service';
|
|
8
|
+
|
|
9
|
+
@Component({
|
|
10
|
+
selector: 'app-root',
|
|
11
|
+
templateUrl: './app.component.html',
|
|
12
|
+
styleUrls: ['./app.component.scss'],
|
|
13
|
+
})
|
|
14
|
+
export class AppComponent implements OnInit {
|
|
15
|
+
constructor(
|
|
16
|
+
private router: Router,
|
|
17
|
+
private routingState: RoutingStateService,
|
|
18
|
+
private store: Store<fromStore.State>,
|
|
19
|
+
private analytics: TimeAnalyticsService,
|
|
20
|
+
) {
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
ngOnInit() {
|
|
24
|
+
// Load auth into store
|
|
25
|
+
this.store.dispatch( new LoadAuth() );
|
|
26
|
+
|
|
27
|
+
// Setup time analytics
|
|
28
|
+
this.analytics.startTimeLogging();
|
|
29
|
+
|
|
30
|
+
// Setup RoutingState to enable retrieving the previous Url
|
|
31
|
+
this.routingState.loadRouting();
|
|
32
|
+
|
|
33
|
+
// Make it so navigating to a new route scrolls back
|
|
34
|
+
this.router.events.subscribe((evt) => {
|
|
35
|
+
if (!(evt instanceof NavigationEnd)) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
document.getElementsByClassName('content-container')[0].scrollTop = 0;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { BrowserModule } from '@angular/platform-browser';
|
|
2
|
+
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
|
3
|
+
import { NgModule } from '@angular/core';
|
|
4
|
+
|
|
5
|
+
import { AppComponent } from './app.component';
|
|
6
|
+
import { AppRoutingModule } from './app-routing.module';
|
|
7
|
+
|
|
8
|
+
// General Modules
|
|
9
|
+
import { CoreModule } from './core/core.module';
|
|
10
|
+
import { SharedModule } from './shared/shared.module';
|
|
11
|
+
|
|
12
|
+
// Feature Modules
|
|
13
|
+
import { GeneralModule } from './general/general.module';
|
|
14
|
+
|
|
15
|
+
@NgModule({
|
|
16
|
+
declarations: [
|
|
17
|
+
AppComponent,
|
|
18
|
+
],
|
|
19
|
+
imports: [
|
|
20
|
+
BrowserModule,
|
|
21
|
+
BrowserAnimationsModule,
|
|
22
|
+
CoreModule,
|
|
23
|
+
SharedModule,
|
|
24
|
+
// Feature Modules
|
|
25
|
+
GeneralModule,
|
|
26
|
+
// Routing Module
|
|
27
|
+
AppRoutingModule,
|
|
28
|
+
],
|
|
29
|
+
providers: [],
|
|
30
|
+
bootstrap: [
|
|
31
|
+
AppComponent,
|
|
32
|
+
],
|
|
33
|
+
})
|
|
34
|
+
export class AppModule { }
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Injectable } from '@angular/core';
|
|
2
|
+
import { LoggingAngularFirestore } from '../setup/firebase-setup';
|
|
3
|
+
import { isDevMode } from '@angular/core';
|
|
4
|
+
|
|
5
|
+
interface LogData {
|
|
6
|
+
__userId: string;
|
|
7
|
+
route: string;
|
|
8
|
+
startTime: number;
|
|
9
|
+
time: Array<{
|
|
10
|
+
total: number;
|
|
11
|
+
type: string;
|
|
12
|
+
}>;
|
|
13
|
+
interactions?: Array<{ 0: number; 1: string; 2: string; 3: string; }>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@Injectable({
|
|
17
|
+
providedIn: 'root',
|
|
18
|
+
})
|
|
19
|
+
export class LogService {
|
|
20
|
+
/** Whether should log to the console in dev. */
|
|
21
|
+
LOG_IN_DEV = true;
|
|
22
|
+
|
|
23
|
+
constructor(
|
|
24
|
+
private log: LoggingAngularFirestore,
|
|
25
|
+
) {
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
rawLog(data: LogData, logType: string = 'logs') {
|
|
29
|
+
if (!isDevMode()) {
|
|
30
|
+
this.log.collection(`/${logType}`).add(data);
|
|
31
|
+
} else if (this.LOG_IN_DEV) {
|
|
32
|
+
console.log(data);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { Injectable } from '@angular/core';
|
|
2
|
+
import { Router, NavigationEnd } from '@angular/router';
|
|
3
|
+
import { Subject, Observable, ConnectableObservable, fromEvent, merge, combineLatest } from 'rxjs';
|
|
4
|
+
import { startWith, withLatestFrom, tap, takeUntil, switchMap, mergeMap, publishReplay, filter, map, pairwise, scan } from 'rxjs/operators';
|
|
5
|
+
import { FirebaseService } from '../firebase/firebase.service';
|
|
6
|
+
import { LogService } from './log.service';
|
|
7
|
+
|
|
8
|
+
export interface TimeAtRoute {
|
|
9
|
+
route: string;
|
|
10
|
+
startTime: number;
|
|
11
|
+
time: Array<{ type: string, total: number }>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface InteractionsAtRoute {
|
|
15
|
+
route: string;
|
|
16
|
+
// We use this typing since Firebase doesn't accept nested arrays
|
|
17
|
+
interactions: Array<{ 0: number, 1: string, 2: string, 3: string }>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@Injectable({
|
|
21
|
+
providedIn: 'root',
|
|
22
|
+
})
|
|
23
|
+
export class TimeAnalyticsService {
|
|
24
|
+
/** Timestamps for all the main user events. */
|
|
25
|
+
private eventTimestamps$: Observable<number>;
|
|
26
|
+
|
|
27
|
+
/** The current route a user is visiting. */
|
|
28
|
+
private currentRoute$: ConnectableObservable<string>;
|
|
29
|
+
|
|
30
|
+
/** The running update of time analytics for each route. */
|
|
31
|
+
private runningTimeAtRoute$: Observable<TimeAtRoute>;
|
|
32
|
+
|
|
33
|
+
/** Only the final time analytics for each route (after navigating to next). */
|
|
34
|
+
private timeAtRoute$: Observable<TimeAtRoute>;
|
|
35
|
+
|
|
36
|
+
/** Events representing different registered interactions. */
|
|
37
|
+
private interactions$: Subject<string> = new Subject<string>();
|
|
38
|
+
|
|
39
|
+
/** Current interactionsAtRoute data. */
|
|
40
|
+
private interactionsAtRoute: InteractionsAtRoute;
|
|
41
|
+
|
|
42
|
+
/** Function that is called by the app to start analytics. */
|
|
43
|
+
public startTimeLogging() {
|
|
44
|
+
// Start logging time
|
|
45
|
+
this.timeAtRoute$.pipe(
|
|
46
|
+
withLatestFrom(this.db.afUser()),
|
|
47
|
+
).subscribe(([timeAtRoute, user]: [TimeAtRoute, { uid: string }]) => {
|
|
48
|
+
if (user && user.uid) {
|
|
49
|
+
if (!this.interactionsAtRoute || !this.interactionsAtRoute.interactions) {
|
|
50
|
+
this.log.rawLog({
|
|
51
|
+
__userId: user.uid,
|
|
52
|
+
...timeAtRoute,
|
|
53
|
+
});
|
|
54
|
+
} else if (timeAtRoute.route === this.interactionsAtRoute.route) {
|
|
55
|
+
this.log.rawLog({
|
|
56
|
+
__userId: user.uid,
|
|
57
|
+
...timeAtRoute,
|
|
58
|
+
interactions: this.interactionsAtRoute.interactions,
|
|
59
|
+
});
|
|
60
|
+
} else {
|
|
61
|
+
console.log('ERROR in time-analytics. Why does route not match?');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
this.currentRoute$.pipe(
|
|
67
|
+
startWith(null as string),
|
|
68
|
+
pairwise(),
|
|
69
|
+
).subscribe(([route1, route2]) => {
|
|
70
|
+
if (!route1 || route1 !== route2) {
|
|
71
|
+
this.interactionsAtRoute = { route: route2, interactions: null };
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Function that can be called by a container to register interactions. */
|
|
77
|
+
public registerInteractions(
|
|
78
|
+
interactions: Array<{ 0: string, 1: string, 2: Observable<any> }>,
|
|
79
|
+
unsubscribe$: Subject<void>,
|
|
80
|
+
) {
|
|
81
|
+
for (const ix of interactions) {
|
|
82
|
+
// Subscribe to each interaction until unsubscribe, and register that the event occured
|
|
83
|
+
ix[2].pipe(
|
|
84
|
+
takeUntil(unsubscribe$),
|
|
85
|
+
).subscribe((data) => {
|
|
86
|
+
let ixLog = { 0: null, 1: null, 2: null, 3: null };
|
|
87
|
+
if (typeof data === 'string' || typeof data === 'number' || typeof data === 'boolean') {
|
|
88
|
+
ixLog = { 0: Date.now(), 1: String(ix[0]), 2: String(ix[1]), 3: String(data) };
|
|
89
|
+
} else {
|
|
90
|
+
ixLog = { 0: Date.now(), 1: String(ix[0]), 2: String(ix[1]), 3: null };
|
|
91
|
+
}
|
|
92
|
+
if (!this.interactionsAtRoute || !this.interactionsAtRoute.interactions) {
|
|
93
|
+
const newInteractions: Array<{ 0: number, 1: string, 2: string, 3: string }> = [ixLog];
|
|
94
|
+
this.interactionsAtRoute.interactions = newInteractions;
|
|
95
|
+
} else {
|
|
96
|
+
this.interactionsAtRoute.interactions.push(ixLog);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
constructor(
|
|
103
|
+
private router: Router,
|
|
104
|
+
private db: FirebaseService,
|
|
105
|
+
private log: LogService,
|
|
106
|
+
) {
|
|
107
|
+
/** Event timestamps from the user. */
|
|
108
|
+
this.eventTimestamps$ = merge(
|
|
109
|
+
fromEvent(document, 'mousemove'),
|
|
110
|
+
fromEvent(document, 'mousedown'),
|
|
111
|
+
fromEvent(document, 'keypress'),
|
|
112
|
+
fromEvent(document, 'click'),
|
|
113
|
+
fromEvent(document, 'scroll'),
|
|
114
|
+
fromEvent(document, 'DOMMouseScroll'),
|
|
115
|
+
fromEvent(document, 'mousewheel'),
|
|
116
|
+
fromEvent(document, 'touchmove'),
|
|
117
|
+
fromEvent(document, 'MSPointerMove'),
|
|
118
|
+
).pipe(
|
|
119
|
+
map(() => Date.now()),
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
/** Tracks the current route in your app. */
|
|
123
|
+
this.currentRoute$ = this.router.events.pipe(
|
|
124
|
+
filter((event) => event instanceof NavigationEnd),
|
|
125
|
+
map(({ urlAfterRedirects }: NavigationEnd) => urlAfterRedirects),
|
|
126
|
+
publishReplay(1),
|
|
127
|
+
) as ConnectableObservable<string>;
|
|
128
|
+
|
|
129
|
+
// Need to manually connect to make sure it gets the first one
|
|
130
|
+
this.currentRoute$.connect();
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
/** Tracks the active time at the current route. */
|
|
134
|
+
this.runningTimeAtRoute$ = combineLatest([this.eventTimestamps$, this.currentRoute$]).pipe(
|
|
135
|
+
pairwise(),
|
|
136
|
+
scan((timeAtRoute, [[timestamp1, route1], [timestamp2, route2]]) => {
|
|
137
|
+
// Amount of inactive time that indicates not working
|
|
138
|
+
// We're using 1 minute for now. Could probably use longer
|
|
139
|
+
// cause people are likely to search for things online, and
|
|
140
|
+
// that shouldn't count as 'inactive' time
|
|
141
|
+
const BREAK_THRESHOLD = 1 * 60 * 1000;
|
|
142
|
+
const interval = timestamp2 - timestamp1;
|
|
143
|
+
const timeToRecord = interval > BREAK_THRESHOLD ? 0 : interval;
|
|
144
|
+
const restToRecord = interval - timeToRecord;
|
|
145
|
+
|
|
146
|
+
if (!timeAtRoute) {
|
|
147
|
+
// If this is the very first event pair
|
|
148
|
+
if (route1 === route2) {
|
|
149
|
+
return {
|
|
150
|
+
route: route1,
|
|
151
|
+
startTime: timestamp1,
|
|
152
|
+
time: [{
|
|
153
|
+
type: 'active',
|
|
154
|
+
total: timeToRecord,
|
|
155
|
+
}],
|
|
156
|
+
};
|
|
157
|
+
} else {
|
|
158
|
+
return {
|
|
159
|
+
route: route2,
|
|
160
|
+
startTime: timestamp1,
|
|
161
|
+
time: [{
|
|
162
|
+
type: 'active',
|
|
163
|
+
total: 0,
|
|
164
|
+
}],
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
} else {
|
|
168
|
+
// For the remainder of events
|
|
169
|
+
if (timeAtRoute.route === route2) {
|
|
170
|
+
const recentTimeEntry = timeAtRoute.time[timeAtRoute.time.length - 1];
|
|
171
|
+
|
|
172
|
+
if (interval === 0) {
|
|
173
|
+
// Some edge cases where the interval could actually be 0
|
|
174
|
+
return timeAtRoute;
|
|
175
|
+
} else if (recentTimeEntry.type === 'active' && timeToRecord > 0) {
|
|
176
|
+
// If this is additional active time, add it to the previous count
|
|
177
|
+
const newRecentTimeEntry = {
|
|
178
|
+
type: 'active', total: recentTimeEntry.total + timeToRecord,
|
|
179
|
+
};
|
|
180
|
+
const newTimeArr = [...timeAtRoute.time.slice(0, timeAtRoute.time.length - 1), newRecentTimeEntry];
|
|
181
|
+
|
|
182
|
+
return { route: route2, startTime: timeAtRoute.startTime, time: newTimeArr };
|
|
183
|
+
} else if (recentTimeEntry.type === 'rest' && timeToRecord > 0) {
|
|
184
|
+
// If this is new active time, make a new entry
|
|
185
|
+
const newTimeArr = [...timeAtRoute.time, {
|
|
186
|
+
type: 'active', total: timeToRecord,
|
|
187
|
+
}];
|
|
188
|
+
return { route: route2, startTime: timeAtRoute.startTime, time: newTimeArr };
|
|
189
|
+
} else {
|
|
190
|
+
// If this is rest time, make a new entry
|
|
191
|
+
const newTimeArr = [...timeAtRoute.time, {
|
|
192
|
+
type: 'rest', total: restToRecord,
|
|
193
|
+
}];
|
|
194
|
+
return { route: route2, startTime: timeAtRoute.startTime, time: newTimeArr };
|
|
195
|
+
}
|
|
196
|
+
} else {
|
|
197
|
+
return {
|
|
198
|
+
route: route2,
|
|
199
|
+
startTime: timestamp2,
|
|
200
|
+
time: [{
|
|
201
|
+
type: 'active', total: 0,
|
|
202
|
+
}],
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}, undefined),
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
this.timeAtRoute$ = this.runningTimeAtRoute$.pipe(
|
|
210
|
+
pairwise(),
|
|
211
|
+
filter(([timeAtRoute1, timeAtRoute2]) => {
|
|
212
|
+
return timeAtRoute2.route !== timeAtRoute1.route;
|
|
213
|
+
}),
|
|
214
|
+
map(([timeAtRoute1, timeAtRoute2]) => timeAtRoute1),
|
|
215
|
+
filter((timeAtRoute: TimeAtRoute) => {
|
|
216
|
+
const total = timeAtRoute.time.reduce((x, y) => {
|
|
217
|
+
return x + y.total;
|
|
218
|
+
}, 0);
|
|
219
|
+
return total > 0;
|
|
220
|
+
}),
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { NgModule, Optional, SkipSelf, NgZone, PLATFORM_ID } from '@angular/core';
|
|
2
|
+
import { CommonModule } from '@angular/common';
|
|
3
|
+
import { RouterModule } from '@angular/router';
|
|
4
|
+
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
|
5
|
+
import { throwIfAlreadyLoaded } from './setup/module-import-guard';
|
|
6
|
+
|
|
7
|
+
import { environment } from '../../environments/environment';
|
|
8
|
+
|
|
9
|
+
// Firebase
|
|
10
|
+
import { AngularFireModule } from '@angular/fire/compat';
|
|
11
|
+
import { AngularFirestoreModule } from '@angular/fire/compat/firestore';
|
|
12
|
+
import { AngularFireAuthModule } from '@angular/fire/compat/auth';
|
|
13
|
+
import { MainAngularFirestore, LoggingAngularFirestore, MainAngularFirestoreFactory, LoggingAngularFirestoreFactory } from './setup/firebase-setup';
|
|
14
|
+
|
|
15
|
+
// NgRx
|
|
16
|
+
import { StoreModule } from '@ngrx/store';
|
|
17
|
+
import { reducers, metaReducers } from './store/app.reducer';
|
|
18
|
+
import { StoreDevtoolsModule } from '@ngrx/store-devtools';
|
|
19
|
+
import { StoreRouterConnectingModule, RouterState } from '@ngrx/router-store';
|
|
20
|
+
import { EffectsModule } from '@ngrx/effects';
|
|
21
|
+
import { AppEffects } from './store/app.effects';
|
|
22
|
+
|
|
23
|
+
// Auth
|
|
24
|
+
import { AuthEffects } from './store/auth/auth.effects';
|
|
25
|
+
|
|
26
|
+
// Entity Effects
|
|
27
|
+
import { UserEffects } from './store/user/user.effects';
|
|
28
|
+
|
|
29
|
+
// Service Effects
|
|
30
|
+
import { SnackbarEffects } from './snackbar/snackbar.effects';
|
|
31
|
+
|
|
32
|
+
@NgModule({
|
|
33
|
+
imports: [
|
|
34
|
+
CommonModule,
|
|
35
|
+
RouterModule,
|
|
36
|
+
BrowserAnimationsModule,
|
|
37
|
+
AngularFireModule.initializeApp(environment.firebase),
|
|
38
|
+
AngularFirestoreModule,
|
|
39
|
+
AngularFireAuthModule,
|
|
40
|
+
StoreModule.forRoot(reducers, {
|
|
41
|
+
metaReducers,
|
|
42
|
+
runtimeChecks: {
|
|
43
|
+
strictActionImmutability: false,
|
|
44
|
+
},
|
|
45
|
+
}),
|
|
46
|
+
StoreRouterConnectingModule.forRoot({ routerState: RouterState.Minimal }),
|
|
47
|
+
StoreDevtoolsModule.instrument({
|
|
48
|
+
maxAge: 25, // Retains last 25 states
|
|
49
|
+
logOnly: environment.production, // Restrict extension to log-only mode
|
|
50
|
+
}),
|
|
51
|
+
EffectsModule.forRoot([
|
|
52
|
+
AppEffects,
|
|
53
|
+
AuthEffects,
|
|
54
|
+
// Service Effects
|
|
55
|
+
SnackbarEffects,
|
|
56
|
+
// Entity Effects
|
|
57
|
+
UserEffects,
|
|
58
|
+
]),
|
|
59
|
+
],
|
|
60
|
+
declarations: [],
|
|
61
|
+
exports: [],
|
|
62
|
+
providers: [
|
|
63
|
+
{ provide: MainAngularFirestore, deps: [PLATFORM_ID, NgZone], useFactory: MainAngularFirestoreFactory },
|
|
64
|
+
{ provide: LoggingAngularFirestore, deps: [PLATFORM_ID, NgZone], useFactory: LoggingAngularFirestoreFactory },
|
|
65
|
+
],
|
|
66
|
+
})
|
|
67
|
+
export class CoreModule {
|
|
68
|
+
constructor(@Optional() @SkipSelf() parentModule: CoreModule) {
|
|
69
|
+
throwIfAlreadyLoaded(parentModule, 'CoreModule');
|
|
70
|
+
}
|
|
71
|
+
}
|