dromo-uploader-angular 0.1.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/README.md +134 -0
- package/karma.conf.js +44 -0
- package/ng-package.json +8 -0
- package/package.json +12 -0
- package/src/lib/dromo-interfaces.ts +16 -0
- package/src/lib/dromo-uploader.component.spec.ts +23 -0
- package/src/lib/dromo-uploader.component.ts +73 -0
- package/src/lib/dromo-uploader.module.ts +37 -0
- package/src/public-api.ts +7 -0
- package/src/test.ts +27 -0
- package/tsconfig.lib.json +15 -0
- package/tsconfig.lib.prod.json +10 -0
- package/tsconfig.spec.json +17 -0
package/README.md
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# [dromo](www.dromo.io)
|
|
2
|
+
|
|
3
|
+
Check out our [developer documentation here](https://developer.dromo.io/)
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
Install the packge using `npm install dromo-uploader-angular`
|
|
8
|
+
|
|
9
|
+
Import the component and module and add to inputs and declarations
|
|
10
|
+
|
|
11
|
+
```TypeScript
|
|
12
|
+
import { DromoImporterComponent } from './dromo-importer/dromo-importer.component';
|
|
13
|
+
import { DromoUploaderComponent } from './dromo-uploader.component';
|
|
14
|
+
|
|
15
|
+
@NgModule({
|
|
16
|
+
declarations: [AppComponent, DromoImporterComponent],
|
|
17
|
+
imports: [BrowserModule, DromoUploaderModule],
|
|
18
|
+
providers: [],
|
|
19
|
+
bootstrap: [AppComponent],
|
|
20
|
+
})
|
|
21
|
+
export class AppModule {}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Implement a component.
|
|
25
|
+
|
|
26
|
+
```TypeScript
|
|
27
|
+
import {
|
|
28
|
+
DromoMethods,
|
|
29
|
+
IColumnHook,
|
|
30
|
+
IColumnHookInput,
|
|
31
|
+
IRowDeleteHook,
|
|
32
|
+
IDeveloperField,
|
|
33
|
+
IDeveloperSettings,
|
|
34
|
+
IRowHook,
|
|
35
|
+
IUser,
|
|
36
|
+
IStepHook,
|
|
37
|
+
IUploadStepData,
|
|
38
|
+
} from 'dromo-uploader-angular';
|
|
39
|
+
@Component({
|
|
40
|
+
selector: 'app-dromo-importer',
|
|
41
|
+
template: `
|
|
42
|
+
<lib-dromo-uploader
|
|
43
|
+
[licenseKey]="licenseKey"
|
|
44
|
+
[user]="user"
|
|
45
|
+
[fields]="fields"
|
|
46
|
+
[settings]="settings"
|
|
47
|
+
[rowHooks]="rowHooks"
|
|
48
|
+
[columnHooks]="columnHooks"
|
|
49
|
+
[stepHooks]="stepHooks"
|
|
50
|
+
[rowDeleteHooks]="rowDeleteHooks"
|
|
51
|
+
[styles]="styles"
|
|
52
|
+
[class]="class"
|
|
53
|
+
class="dromo-importer"
|
|
54
|
+
[onCancel]="onCancel"
|
|
55
|
+
[onResults]="onResults"
|
|
56
|
+
>Import with Dromo!</lib-dromo-uploader
|
|
57
|
+
>
|
|
58
|
+
`,
|
|
59
|
+
styleUrls: ['./dromo-importer.component.css'],
|
|
60
|
+
})
|
|
61
|
+
export class DromoImporterComponent implements DromoMethods {
|
|
62
|
+
constructor() {}
|
|
63
|
+
|
|
64
|
+
licenseKey = 'YOUR_LICENSE_KEY_HERE';
|
|
65
|
+
user: IUser = { id: 'angular tester' };
|
|
66
|
+
fields: IDeveloperField[] = [
|
|
67
|
+
{ label: 'first name', key: 'first_name' },
|
|
68
|
+
{ label: 'email address', key: 'email' },
|
|
69
|
+
];
|
|
70
|
+
settings: IDeveloperSettings = {
|
|
71
|
+
importIdentifier: 'angular imports',
|
|
72
|
+
developmentMode: true,
|
|
73
|
+
};
|
|
74
|
+
rowHooks: IRowHook[] = [
|
|
75
|
+
(record) => {
|
|
76
|
+
const newRecord = { ...record };
|
|
77
|
+
newRecord.row['first_name'].value =
|
|
78
|
+
record.row['first_name'].value + '!!!';
|
|
79
|
+
return newRecord;
|
|
80
|
+
},
|
|
81
|
+
];
|
|
82
|
+
rowDeleteHooks: IRowDeleteHook[] = [
|
|
83
|
+
(record) => alert(`deleted ${record.index}`),
|
|
84
|
+
];
|
|
85
|
+
columnHooks: IColumnHook[] = [
|
|
86
|
+
{
|
|
87
|
+
fieldName: 'email',
|
|
88
|
+
callback: (values: IColumnHookInput[]) => {
|
|
89
|
+
console.log('COLUMN HOOK', values);
|
|
90
|
+
values = values.map(({ value, index }) => ({
|
|
91
|
+
value: index + value,
|
|
92
|
+
index,
|
|
93
|
+
}));
|
|
94
|
+
return values;
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
];
|
|
98
|
+
|
|
99
|
+
stepHooks: IStepHook[] = [
|
|
100
|
+
{
|
|
101
|
+
type: 'UPLOAD_STEP',
|
|
102
|
+
callback: (uploader, data) => {
|
|
103
|
+
console.log(
|
|
104
|
+
'STEP HOOK',
|
|
105
|
+
`Filename: ${(data as IUploadStepData).filename}`
|
|
106
|
+
);
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
];
|
|
110
|
+
|
|
111
|
+
onCancel = () => alert('Something I said?');
|
|
112
|
+
onResults = (data: any[], metaData: any) => {
|
|
113
|
+
alert(`Submitted ${data.length} records`);
|
|
114
|
+
console.table(data);
|
|
115
|
+
console.log('MetaData', metaData);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
class = 'dromo-button';
|
|
119
|
+
styles = {
|
|
120
|
+
'background-color': 'rgb(0, 123, 255)',
|
|
121
|
+
border: '1px solid rgb(0, 123, 255)',
|
|
122
|
+
'border-radius': ' 0.25rem',
|
|
123
|
+
color: 'white',
|
|
124
|
+
padding: '15px',
|
|
125
|
+
'text-align': 'center',
|
|
126
|
+
'text-decoration': 'none',
|
|
127
|
+
display: 'inline-block',
|
|
128
|
+
'font-size': '16px',
|
|
129
|
+
'box-shadow': '5px 5px 5px 0px #7F7F7F',
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
ngOnInit(): void {}
|
|
133
|
+
}
|
|
134
|
+
```
|
package/karma.conf.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Karma configuration file, see link for more information
|
|
2
|
+
// https://karma-runner.github.io/1.0/config/configuration-file.html
|
|
3
|
+
|
|
4
|
+
module.exports = function (config) {
|
|
5
|
+
config.set({
|
|
6
|
+
basePath: "",
|
|
7
|
+
frameworks: ["jasmine", "@angular-devkit/build-angular"],
|
|
8
|
+
plugins: [
|
|
9
|
+
require("karma-jasmine"),
|
|
10
|
+
require("karma-chrome-launcher"),
|
|
11
|
+
require("karma-jasmine-html-reporter"),
|
|
12
|
+
require("karma-coverage"),
|
|
13
|
+
require("@angular-devkit/build-angular/plugins/karma"),
|
|
14
|
+
],
|
|
15
|
+
client: {
|
|
16
|
+
jasmine: {
|
|
17
|
+
// you can add configuration options for Jasmine here
|
|
18
|
+
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
|
|
19
|
+
// for example, you can disable the random execution with `random: false`
|
|
20
|
+
// or set a specific seed with `seed: 4321`
|
|
21
|
+
},
|
|
22
|
+
clearContext: false, // leave Jasmine Spec Runner output visible in browser
|
|
23
|
+
},
|
|
24
|
+
jasmineHtmlReporter: {
|
|
25
|
+
suppressAll: true, // removes the duplicated traces
|
|
26
|
+
},
|
|
27
|
+
coverageReporter: {
|
|
28
|
+
dir: require("path").join(
|
|
29
|
+
__dirname,
|
|
30
|
+
"../../coverage/dromo-uploader-angular"
|
|
31
|
+
),
|
|
32
|
+
subdir: ".",
|
|
33
|
+
reporters: [{ type: "html" }, { type: "text-summary" }],
|
|
34
|
+
},
|
|
35
|
+
reporters: ["progress", "kjhtml"],
|
|
36
|
+
port: 9876,
|
|
37
|
+
colors: true,
|
|
38
|
+
logLevel: config.LOG_INFO,
|
|
39
|
+
autoWatch: true,
|
|
40
|
+
browsers: ["Chrome"],
|
|
41
|
+
singleRun: false,
|
|
42
|
+
restartOnFileChange: true,
|
|
43
|
+
});
|
|
44
|
+
};
|
package/ng-package.json
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "dromo-uploader-angular",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"peerDependencies": {
|
|
5
|
+
"@angular/common": "^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0",
|
|
6
|
+
"@angular/core": "^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0"
|
|
7
|
+
},
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"dromo-uploader-js": "^1.2.28",
|
|
10
|
+
"tslib": "^2.0.0"
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type {
|
|
2
|
+
IDeveloperField,
|
|
3
|
+
IDeveloperSettings,
|
|
4
|
+
IUser,
|
|
5
|
+
IColumnHookInput,
|
|
6
|
+
IColumnHookOutput,
|
|
7
|
+
IColumnHook,
|
|
8
|
+
IRowHookInput,
|
|
9
|
+
IRowHookOutput,
|
|
10
|
+
IRowHook,
|
|
11
|
+
IValidatorField,
|
|
12
|
+
IDeveloperStyleOverrides,
|
|
13
|
+
IRowDeleteHook,
|
|
14
|
+
IStepHook,
|
|
15
|
+
IUploadStepData,
|
|
16
|
+
} from 'dromo-uploader-js';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
2
|
+
|
|
3
|
+
import { DromoUploaderComponent } from './dromo-uploader.component';
|
|
4
|
+
|
|
5
|
+
describe('DromoUploaderComponent', () => {
|
|
6
|
+
let component: DromoUploaderComponent;
|
|
7
|
+
let fixture: ComponentFixture<DromoUploaderComponent>;
|
|
8
|
+
|
|
9
|
+
beforeEach(async () => {
|
|
10
|
+
await TestBed.configureTestingModule({
|
|
11
|
+
declarations: [ DromoUploaderComponent ]
|
|
12
|
+
})
|
|
13
|
+
.compileComponents();
|
|
14
|
+
|
|
15
|
+
fixture = TestBed.createComponent(DromoUploaderComponent);
|
|
16
|
+
component = fixture.componentInstance;
|
|
17
|
+
fixture.detectChanges();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should create', () => {
|
|
21
|
+
expect(component).toBeTruthy();
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Component, OnInit, Input } from '@angular/core';
|
|
2
|
+
import DromoUploader, {
|
|
3
|
+
IDeveloperSettings,
|
|
4
|
+
IUser,
|
|
5
|
+
IDeveloperField,
|
|
6
|
+
IRowHook,
|
|
7
|
+
IColumnHook,
|
|
8
|
+
IRowDeleteHook,
|
|
9
|
+
} from 'dromo-uploader-js';
|
|
10
|
+
import { IResultMetadata, IStepHook } from 'dromo-uploader-js/dist/interfaces';
|
|
11
|
+
|
|
12
|
+
@Component({
|
|
13
|
+
selector: 'lib-dromo-uploader',
|
|
14
|
+
template: `
|
|
15
|
+
<button (click)="openDromo()" [classList]="class" [ngStyle]="styles">
|
|
16
|
+
<ng-content></ng-content>
|
|
17
|
+
</button>
|
|
18
|
+
`,
|
|
19
|
+
})
|
|
20
|
+
export class DromoUploaderComponent implements OnInit {
|
|
21
|
+
@Input() settings!: IDeveloperSettings;
|
|
22
|
+
@Input() user!: IUser;
|
|
23
|
+
@Input() licenseKey!: string;
|
|
24
|
+
@Input() fields!: IDeveloperField[];
|
|
25
|
+
@Input() rowHooks: IRowHook[] = [];
|
|
26
|
+
@Input() columnHooks: IColumnHook[] = [];
|
|
27
|
+
@Input() rowDeleteHooks: IRowDeleteHook[] = [];
|
|
28
|
+
@Input() onResults: (
|
|
29
|
+
data: any[],
|
|
30
|
+
metaData: IResultMetadata
|
|
31
|
+
) => Promise<void> | void = () => undefined;
|
|
32
|
+
@Input() onCancel: () => void = () => undefined;
|
|
33
|
+
@Input() stepHooks: IStepHook[] = [];
|
|
34
|
+
@Input() class: string = '';
|
|
35
|
+
@Input() styles: {} = {};
|
|
36
|
+
|
|
37
|
+
dromo?: DromoUploader;
|
|
38
|
+
|
|
39
|
+
constructor() {}
|
|
40
|
+
|
|
41
|
+
openDromo() {
|
|
42
|
+
if (this.dromo) {
|
|
43
|
+
this.dromo.open();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
ngOnInit(): void {
|
|
48
|
+
this.dromo = new DromoUploader(
|
|
49
|
+
this.licenseKey,
|
|
50
|
+
this.fields,
|
|
51
|
+
this.settings,
|
|
52
|
+
this.user
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
this.rowHooks.forEach((hook) => this.dromo?.registerRowHook(hook));
|
|
56
|
+
|
|
57
|
+
this.columnHooks.forEach((hook) => {
|
|
58
|
+
this.dromo?.registerColumnHook(hook.fieldName, hook.callback);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
this.rowDeleteHooks.forEach((hook) => {
|
|
62
|
+
return this.dromo?.registerRowDeleteHook(hook);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
this.stepHooks.forEach((hook) => {
|
|
66
|
+
this.dromo?.registerStepHook(hook.type, hook.callback);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
this.dromo.onResults(this.onResults);
|
|
70
|
+
|
|
71
|
+
this.dromo.onCancel(this.onCancel);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { NgModule } from '@angular/core';
|
|
2
|
+
import { CommonModule } from '@angular/common';
|
|
3
|
+
import { DromoUploaderComponent } from './dromo-uploader.component';
|
|
4
|
+
import {
|
|
5
|
+
IUser,
|
|
6
|
+
IDeveloperSettings,
|
|
7
|
+
IDeveloperField,
|
|
8
|
+
IRowHook,
|
|
9
|
+
IRowDeleteHook,
|
|
10
|
+
IColumnHook,
|
|
11
|
+
} from 'dromo-uploader-js';
|
|
12
|
+
import { IResultMetadata, IStepHook } from 'dromo-uploader-js/dist/interfaces';
|
|
13
|
+
|
|
14
|
+
@NgModule({
|
|
15
|
+
declarations: [DromoUploaderComponent],
|
|
16
|
+
imports: [CommonModule],
|
|
17
|
+
exports: [DromoUploaderComponent, CommonModule],
|
|
18
|
+
})
|
|
19
|
+
export class DromoUploaderModule {}
|
|
20
|
+
|
|
21
|
+
export interface DromoMethods {
|
|
22
|
+
licenseKey: string;
|
|
23
|
+
user: IUser;
|
|
24
|
+
settings: IDeveloperSettings;
|
|
25
|
+
fields: IDeveloperField[];
|
|
26
|
+
rowHooks?: IRowHook[];
|
|
27
|
+
rowDeleteHooks?: IRowDeleteHook[];
|
|
28
|
+
columnHooks?: IColumnHook[];
|
|
29
|
+
stepHooks?: IStepHook[];
|
|
30
|
+
style?: {};
|
|
31
|
+
class?: string;
|
|
32
|
+
onCancel?: () => void;
|
|
33
|
+
onResults?: (
|
|
34
|
+
data: any[][],
|
|
35
|
+
metaData: IResultMetadata
|
|
36
|
+
) => Promise<void> | void;
|
|
37
|
+
}
|
package/src/test.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
|
|
2
|
+
|
|
3
|
+
import 'zone.js';
|
|
4
|
+
import 'zone.js/testing';
|
|
5
|
+
import { getTestBed } from '@angular/core/testing';
|
|
6
|
+
import {
|
|
7
|
+
BrowserDynamicTestingModule,
|
|
8
|
+
platformBrowserDynamicTesting
|
|
9
|
+
} from '@angular/platform-browser-dynamic/testing';
|
|
10
|
+
|
|
11
|
+
declare const require: {
|
|
12
|
+
context(path: string, deep?: boolean, filter?: RegExp): {
|
|
13
|
+
<T>(id: string): T;
|
|
14
|
+
keys(): string[];
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// First, initialize the Angular testing environment.
|
|
19
|
+
getTestBed().initTestEnvironment(
|
|
20
|
+
BrowserDynamicTestingModule,
|
|
21
|
+
platformBrowserDynamicTesting(),
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
// Then we find all the tests.
|
|
25
|
+
const context = require.context('./', true, /\.spec\.ts$/);
|
|
26
|
+
// And load the modules.
|
|
27
|
+
context.keys().forEach(context);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
|
2
|
+
{
|
|
3
|
+
"extends": "../../tsconfig.json",
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"outDir": "../../out-tsc/lib",
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"declarationMap": true,
|
|
8
|
+
"inlineSources": true,
|
|
9
|
+
"types": []
|
|
10
|
+
},
|
|
11
|
+
"exclude": [
|
|
12
|
+
"src/test.ts",
|
|
13
|
+
"**/*.spec.ts"
|
|
14
|
+
]
|
|
15
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
|
2
|
+
{
|
|
3
|
+
"extends": "../../tsconfig.json",
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"outDir": "../../out-tsc/spec",
|
|
6
|
+
"types": [
|
|
7
|
+
"jasmine"
|
|
8
|
+
]
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"src/test.ts"
|
|
12
|
+
],
|
|
13
|
+
"include": [
|
|
14
|
+
"**/*.spec.ts",
|
|
15
|
+
"**/*.d.ts"
|
|
16
|
+
]
|
|
17
|
+
}
|