Skip to content

Commit

Permalink
Merge pull request #23 from bigBear713/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
bigBear713 authored May 23, 2023
2 parents 1a8e6ea + 7c483d4 commit 5c226f2
Show file tree
Hide file tree
Showing 16 changed files with 171 additions and 31 deletions.
1 change: 0 additions & 1 deletion docs/249.179c4a768e318e00.js

This file was deleted.

1 change: 1 addition & 0 deletions docs/249.d275b82b7ed83afa.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 25 additions & 13 deletions docs/3rdpartylicenses.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,31 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

dayjs
MIT
MIT License

Copyright (c) 2018-present, iamkun

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


lodash-es
MIT
Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
Expand Down Expand Up @@ -342,19 +367,6 @@ Apache-2.0



uuid
MIT
The MIT License (MIT)

Copyright (c) 2010-2020 Robert Kieffer and other contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


zone.js
MIT
The MIT License
Expand Down
15 changes: 14 additions & 1 deletion docs/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,22 @@
<base href="/nb-form/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<!-- Google tag (gtag.js) -->
<script async="" src="https://www.googletagmanager.com/gtag/js?id=G-2C00ZKDNJZ"></script>
<script>
window.website_ga_id = 'G-2C00ZKDNJZ';
window.libs_ga_id = 'G-V3SHZ9LQWZ';
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
window.gtag = gtag;
gtag('js', new Date());
gtag('config', window.website_ga_id);
gtag('config', window.libs_ga_id);
</script>
<link rel="stylesheet" href="styles.ef46db3751d8e999.css"></head>

<body>
<app-root></app-root>
<script src="runtime.1b581a2fa8e17068.js" type="module"></script><script src="polyfills.0d1c48b529314817.js" type="module"></script><script src="main.5ffd59aeb02c8694.js" type="module"></script>
<script src="runtime.3cd40b0b2425fe70.js" type="module"></script><script src="polyfills.ce94525ff22a9194.js" type="module"></script><script src="main.9c38bb6ce43366a8.js" type="module"></script>

</body></html>
15 changes: 14 additions & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,22 @@
<base href="/nb-form/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<!-- Google tag (gtag.js) -->
<script async="" src="https://www.googletagmanager.com/gtag/js?id=G-2C00ZKDNJZ"></script>
<script>
window.website_ga_id = 'G-2C00ZKDNJZ';
window.libs_ga_id = 'G-V3SHZ9LQWZ';
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
window.gtag = gtag;
gtag('js', new Date());
gtag('config', window.website_ga_id);
gtag('config', window.libs_ga_id);
</script>
<link rel="stylesheet" href="styles.ef46db3751d8e999.css"></head>

<body>
<app-root></app-root>
<script src="runtime.1b581a2fa8e17068.js" type="module"></script><script src="polyfills.0d1c48b529314817.js" type="module"></script><script src="main.5ffd59aeb02c8694.js" type="module"></script>
<script src="runtime.3cd40b0b2425fe70.js" type="module"></script><script src="polyfills.ce94525ff22a9194.js" type="module"></script><script src="main.9c38bb6ce43366a8.js" type="module"></script>

</body></html>
1 change: 0 additions & 1 deletion docs/main.5ffd59aeb02c8694.js

This file was deleted.

1 change: 1 addition & 0 deletions docs/main.9c38bb6ce43366a8.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion docs/polyfills.0d1c48b529314817.js

This file was deleted.

1 change: 1 addition & 0 deletions docs/polyfills.ce94525ff22a9194.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion docs/runtime.1b581a2fa8e17068.js

This file was deleted.

1 change: 1 addition & 0 deletions docs/runtime.3cd40b0b2425fe70.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@angular/router": "^16.0.0",
"@bigbear713/nb-common": "^16.0.0",
"@bigbear713/nb-trans": "^16.0.0",
"dayjs": "^1.11.7",
"lodash-es": "^4.17.21",
"rxjs": "~6.6.0",
"tslib": "^2.3.0",
Expand All @@ -53,4 +54,4 @@
"source-map-explorer": "^2.5.2",
"typescript": "~5.0.4"
}
}
}
8 changes: 2 additions & 6 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<h2>
<a href="https://github.com/bigBear713/nb-form/blob/master/projects/nb-form/README.md" target="_blank">
Document
</a>
<a href="https://github.com/bigBear713/nb-form/blob/master/CHANGELOG.md" target="_blank">
Changelog
</a>
<a [href]="links.document.link" target="_blank" (click)="go2Link(links.document)"> {{links.document.title}} </a>
<a [href]="links.changelog.link" target="_blank" (click)="go2Link(links.changelog)"> {{links.changelog.title}} </a>
</h2>
<hr>
<h3>
Expand Down
44 changes: 40 additions & 4 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Component, OnInit } from '@angular/core';
import { UntypedFormBuilder, UntypedFormControl, UntypedFormGroup } from '@angular/forms';
import { NbTransLangEnum, NbTransService } from '@bigbear713/nb-trans';
import { NbTransLang, NbTransService } from '@bigbear713/nb-trans';
import { NbControlErrType, NbFormService, NbFormValidators } from 'nb-form';
import { GTagService } from './g-tag.service';

@Component({
selector: 'app-root',
Expand All @@ -21,6 +22,17 @@ export class AppComponent implements OnInit {
[NbControlErrType.FILE_MAX_SIZE]: 'The file max size is 500kb!',
};

links = {
changelog: {
title: 'Changelog',
link: 'https://github.com/bigBear713/nb-form/blob/master/CHANGELOG.md',
},
document: {
title: 'Document',
link: 'https://github.com/bigBear713/nb-form/blob/master/projects/nb-form/README.md',
},
};

get field1Ctrl(): UntypedFormControl {
return this.form?.get('field1') as UntypedFormControl;
}
Expand Down Expand Up @@ -48,23 +60,38 @@ export class AppComponent implements OnInit {
constructor(
private fb: UntypedFormBuilder,
private formService: NbFormService,
private gtagService: GTagService,
private transService: NbTransService,
) { }

ngOnInit(): void {
this.trackPage();
this.buildForm();
// you can use it to unsubscribe when destroy the form/component
const subscription = this.formService.updateEqualControlsValidities({ target: this.field4Ctrl, compared: this.field5Ctrl });
}

changeLanguage(langKey: string) {
this.transService.changeLangSync(
langKey === 'en' ? NbTransLangEnum.EN : NbTransLangEnum.ZH_CN
);
const lang = langKey === 'en' ? NbTransLang.EN : NbTransLang.ZH_CN;
this.transService.changeLangSync(lang);
this.gtagService.trackButton({
button_name: 'zh-CN' === lang ? '切换为中文' : 'switch as English',
language: lang,
});
}

go2Link(target: { title: string, link: string }): void {
this.gtagService.trackLink({
link_name: target.title,
link: target.link,
});
}

resetCtrl1() {
this.field1Ctrl.reset();
this.gtagService.trackButton({
button_name: 'reset field',
});
}

onChangeFile($event: Event): void {
Expand All @@ -77,6 +104,9 @@ export class AppComponent implements OnInit {

onSubmit() {
this.formService.showAllErrInfo(this.form);
this.gtagService.trackButton({
button_name: 'submit',
});
}

private buildForm(): void {
Expand All @@ -96,4 +126,10 @@ export class AppComponent implements OnInit {

this.field6Ctrl.markAsDirty();
}

private trackPage() {
this.gtagService.trackPage({
page_name: 'homepage',
});
}
}
54 changes: 54 additions & 0 deletions src/app/g-tag.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { NbTransService } from '@bigbear713/nb-trans';
import * as dayjs from 'dayjs';
import * as utc from 'dayjs/plugin/utc';
dayjs.extend(utc);

const defaultGtag = () => { };
const gtag = (window as any).gtag || defaultGtag;

const website_id = '@bigbear713/nb-form';
const website_ga_id = (window as any).website_ga_id;
const libs_ga_id = (window as any).libs_ga_id;

@Injectable({
providedIn: 'root'
})
export class GTagService {

constructor(
private router: Router,
private transService: NbTransService,
) { }

trackPage(props: object): void {
this.trackEvent('View_Page', props);
}

trackButton(props: object): void {
this.trackEvent('Click_Button', props);
}

trackLink(props: object): void {
this.trackEvent('Visit_Link', props);
}

private trackEvent(eventName: string, props: object): void {
const trackCurrProps = {
send_to: website_ga_id,
datetime: dayjs().utc().format(),
url: this.router.url,
language: this.transService.lang,
...props,
};
const trackLibsProps = {
...trackCurrProps,
send_to: libs_ga_id,
website_id,
};
gtag('event', eventName, trackCurrProps);
gtag('event', eventName, trackLibsProps);
}

}
17 changes: 16 additions & 1 deletion src/index.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
<!doctype html>
<html>

<head>
<meta charset="utf-8">
<title>NbForm</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-2C00ZKDNJZ"></script>
<script>
window.website_ga_id = 'G-2C00ZKDNJZ';
window.libs_ga_id = 'G-V3SHZ9LQWZ';
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
window.gtag = gtag;
gtag('js', new Date());
gtag('config', window.website_ga_id);
gtag('config', window.libs_ga_id);
</script>
</head>

<body>
<app-root></app-root>
</body>
</html>

</html>

0 comments on commit 5c226f2

Please sign in to comment.