@kigi/components 1.5.11 → 1.5.12
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 +5 -4
- package/src/components/index.ts +2 -0
- package/src/components/mbg-image-upload/helpers/firebase.ts +79 -55
- package/src/components/mbg-image-upload-crop/image-upload-crop.html +24 -0
- package/src/components/mbg-image-upload-crop/image-upload-crop.scss +76 -0
- package/src/components/mbg-image-upload-crop/image-upload-crop.ts +50 -0
- package/src/components/mbg-image-upload-crop/index.ts +9 -0
- package/src/components/mbg-image-upload-crop/interfaces/config-image-upload-crop.interface.ts +9 -0
- package/src/components/mbg-image-upload-crop/modals/upload-image-crop-modal/index.ts +31 -0
- package/src/components/mbg-image-upload-crop/modals/upload-image-crop-modal/upload-image-crop-modal.html +71 -0
- package/src/components/mbg-image-upload-crop/modals/upload-image-crop-modal/upload-image-crop-modal.scss +140 -0
- package/src/components/mbg-image-upload-crop/modals/upload-image-crop-modal/upload-image-crop-modal.ts +151 -0
- package/src/index.html +8 -1
- package/src/index.ts +14 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kigi/components",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.12",
|
|
4
4
|
"description": "@kigi/components",
|
|
5
5
|
"main": "src/components/index.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"@syncfusion/ej2-navigations": "^17.4.43",
|
|
39
39
|
"@syncfusion/ej2-splitbuttons": "^17.4.43",
|
|
40
40
|
"@types/node": "^10.10.1",
|
|
41
|
+
"ace-builds": "1.3.3",
|
|
41
42
|
"angular": "1.7.9",
|
|
42
43
|
"angular-animate": "^1.7.9",
|
|
43
44
|
"angular-bootstrap": "^0.12.2",
|
|
@@ -50,9 +51,10 @@
|
|
|
50
51
|
"angular-ui-bootstrap": "^2.5.6",
|
|
51
52
|
"angular-vs-repeat": "^2.0.14",
|
|
52
53
|
"cep-promise": "^3.0.3",
|
|
54
|
+
"cropperjs": "^1.5.12",
|
|
53
55
|
"croppie": "^2.6.2",
|
|
54
56
|
"detect-browser": "^3.0.1",
|
|
55
|
-
"firebase": "
|
|
57
|
+
"firebase": "7.16.0",
|
|
56
58
|
"fuse.js": "^3.4.6",
|
|
57
59
|
"grpc": "1.20.2",
|
|
58
60
|
"highcharts": "^6.1.0",
|
|
@@ -71,8 +73,7 @@
|
|
|
71
73
|
"progressbar.js": "^1.0.1",
|
|
72
74
|
"raphael": "^2.2.8",
|
|
73
75
|
"sugarss": "^2.0.0",
|
|
74
|
-
"webcamjs": "^1.0.25"
|
|
75
|
-
"ace-builds": "1.3.3"
|
|
76
|
+
"webcamjs": "^1.0.25"
|
|
76
77
|
},
|
|
77
78
|
"devDependencies": {
|
|
78
79
|
"@types/angular": "^1.6.27",
|
package/src/components/index.ts
CHANGED
|
@@ -84,6 +84,7 @@ import { mbgTextEditorModule } from './mbg-text-editor'
|
|
|
84
84
|
import 'jodit/src/langs/pt_br.js'
|
|
85
85
|
import { NgMaskIe } from '../helpers/ie-directive/ie-directive'
|
|
86
86
|
import { mbgAceEditorModule } from './mbg-ace-editor'
|
|
87
|
+
import { mbgImageUploadCropModule } from './mbg-image-upload-crop'
|
|
87
88
|
|
|
88
89
|
if (!window['$']) {
|
|
89
90
|
window['$'] = $
|
|
@@ -100,6 +101,7 @@ const mbgComponentsModule = angular
|
|
|
100
101
|
ngSanitize,
|
|
101
102
|
ngAnimate,
|
|
102
103
|
mbgImageUploadModule,
|
|
104
|
+
mbgImageUploadCropModule,
|
|
103
105
|
mbgInputCnpjModule,
|
|
104
106
|
mbgInputCpfModule,
|
|
105
107
|
mbgInputCpfCnpjModule,
|
|
@@ -2,66 +2,90 @@ import firebase from 'firebase/app'
|
|
|
2
2
|
import 'firebase/storage'
|
|
3
3
|
|
|
4
4
|
export namespace ImageUploadFirebase {
|
|
5
|
-
|
|
5
|
+
const URL_FIREBASE = 'https://firebasestorage.googleapis.com/v0/b/bucket/o/id?alt=media'
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
export function getStorage(): any {
|
|
8
|
+
return window['firebase'] ? window['firebase'].storage() : firebase.storage()
|
|
9
|
+
}
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
export function guid() {
|
|
12
|
+
const s4 = () =>
|
|
13
|
+
Math.floor((1 + Math.random()) * 0x10000)
|
|
14
|
+
.toString(16)
|
|
15
|
+
.substring(1)
|
|
16
|
+
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4()
|
|
17
|
+
}
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
export async function removeFiles(files) {
|
|
20
|
+
files.forEach((file) => {
|
|
21
|
+
if (file) {
|
|
22
|
+
const storageRef = getStorage().ref().child(file.idStorage)
|
|
23
|
+
storageRef.delete()
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
}
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const storageRef = getStorage().ref().child(folder ? `${folder}/${imageID}` : imageID)
|
|
31
|
-
const response = await storageRef.putString(base64, 'data_url')
|
|
32
|
-
const imageURL = folder ? URL_FIREBASE.replace(/bucket/g, response.metadata.bucket).replace(/id/g, `${folder}%2F${response.metadata.name}`)
|
|
33
|
-
: URL_FIREBASE.replace(/bucket/g, response.metadata.bucket).replace(/id/g, response.metadata.name)
|
|
34
|
-
const image = { url: imageURL, idStorage: imageID }
|
|
35
|
-
return image
|
|
36
|
-
}))
|
|
37
|
-
}
|
|
38
|
-
export function uploadFile(file: File, config: { onProgress, onPause, onResume, onError, onSuccess }, folder = '') {
|
|
28
|
+
export async function upload(files: Array<string>, folder = '') {
|
|
29
|
+
return await Promise.all(
|
|
30
|
+
files.map(async (base64) => {
|
|
39
31
|
const imageID = this.guid()
|
|
40
|
-
const storageRef = getStorage()
|
|
41
|
-
|
|
32
|
+
const storageRef = getStorage()
|
|
33
|
+
.ref()
|
|
34
|
+
.child(folder ? `${folder}/${imageID}` : imageID)
|
|
35
|
+
const response = await storageRef.putString(base64, 'data_url')
|
|
36
|
+
const imageURL = folder
|
|
37
|
+
? URL_FIREBASE.replace(/bucket/g, response.metadata.bucket).replace(
|
|
38
|
+
/id/g,
|
|
39
|
+
`${folder}%2F${response.metadata.name}`,
|
|
40
|
+
)
|
|
41
|
+
: URL_FIREBASE.replace(/bucket/g, response.metadata.bucket).replace(
|
|
42
|
+
/id/g,
|
|
43
|
+
response.metadata.name,
|
|
44
|
+
)
|
|
45
|
+
const image = { url: imageURL, idStorage: imageID }
|
|
46
|
+
return image
|
|
47
|
+
}),
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
export function uploadFile(
|
|
51
|
+
file: File,
|
|
52
|
+
config: { onProgress; onPause; onResume; onError; onSuccess },
|
|
53
|
+
folder = '',
|
|
54
|
+
) {
|
|
55
|
+
const imageID = this.guid()
|
|
56
|
+
const storageRef = getStorage()
|
|
57
|
+
.ref()
|
|
58
|
+
.child(folder ? `${folder}/${imageID}` : imageID)
|
|
59
|
+
const uploadTask = storageRef.put(file)
|
|
42
60
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
61
|
+
uploadTask.on(
|
|
62
|
+
'state_changed',
|
|
63
|
+
(snapshot) => {
|
|
64
|
+
const progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100
|
|
65
|
+
config.onProgress(progress)
|
|
66
|
+
switch (snapshot.state) {
|
|
67
|
+
case firebase.storage.TaskState.PAUSED:
|
|
68
|
+
config.onPause()
|
|
69
|
+
break
|
|
70
|
+
case firebase.storage.TaskState.RUNNING:
|
|
71
|
+
config.onResume()
|
|
72
|
+
break
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
(e) => {
|
|
76
|
+
config.onError()
|
|
77
|
+
},
|
|
78
|
+
() => {
|
|
79
|
+
uploadTask.snapshot.ref
|
|
80
|
+
.getDownloadURL()
|
|
81
|
+
.then((downloadURL) => {
|
|
82
|
+
config.onSuccess({ fileName: file.name, fileURL: downloadURL, fileSize: file.size })
|
|
83
|
+
})
|
|
84
|
+
.catch(() => {
|
|
55
85
|
config.onError()
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
.catch(() => {
|
|
62
|
-
config.onError()
|
|
63
|
-
})
|
|
64
|
-
})
|
|
65
|
-
return uploadTask
|
|
66
|
-
}
|
|
86
|
+
})
|
|
87
|
+
},
|
|
88
|
+
)
|
|
89
|
+
return uploadTask
|
|
90
|
+
}
|
|
67
91
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<div class="image-upload-crop-wrapper"
|
|
2
|
+
ng-style="{ 'width': $ctrl.config.width ? $ctrl.config.width : '200px', 'height': $ctrl.config.height ? $ctrl.config.height : '84px'}">
|
|
3
|
+
<div class="upload-item"
|
|
4
|
+
ng-style="{'cursor': $ctrl.ngModel ? 'default' : 'pointer'}"
|
|
5
|
+
ng-click="!$ctrl.ngModel && $ctrl.openModal()">
|
|
6
|
+
<div class="preview-image-crop"
|
|
7
|
+
ng-show="$ctrl.ngModel"
|
|
8
|
+
ng-click="$ctrl.openModal()">
|
|
9
|
+
<img ng-show="$ctrl.ngModel"
|
|
10
|
+
ng-style="{ 'object-fit': 'contain', 'width': '100%'}"
|
|
11
|
+
src="{{$ctrl.ngModel}}">
|
|
12
|
+
</div>
|
|
13
|
+
<div class="icon-upload-image-crop">
|
|
14
|
+
<i ng-show="!$ctrl.ngModel"
|
|
15
|
+
class="fas fa-cloud-upload-alt"></i>
|
|
16
|
+
<div class="buttons"
|
|
17
|
+
ng-class="{'remove': $ctrl.ngModel}">
|
|
18
|
+
<a ng-click="$ctrl.removeImage($event)">{{$ctrl.ngModel ? 'Remover' : ''}}</a>
|
|
19
|
+
<a ng-click="$ctrl.openModal()">{{$ctrl.ngModel ? 'Alterar' : 'Fazer upload'}}</a>
|
|
20
|
+
</div>
|
|
21
|
+
</div>
|
|
22
|
+
|
|
23
|
+
</div>
|
|
24
|
+
</div>
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
.image-upload-crop-wrapper {
|
|
2
|
+
.upload-item {
|
|
3
|
+
padding: 4px;
|
|
4
|
+
border: 1px dashed #9c9c9c;
|
|
5
|
+
border-radius: 4px;
|
|
6
|
+
display: flex;
|
|
7
|
+
flex-direction: column;
|
|
8
|
+
width: 100%;
|
|
9
|
+
transition: all 300ms ease-in-out;
|
|
10
|
+
height: 100%;
|
|
11
|
+
margin-top: 10px;
|
|
12
|
+
position: relative;
|
|
13
|
+
text-align: center;
|
|
14
|
+
align-items: center;
|
|
15
|
+
justify-content: center;
|
|
16
|
+
|
|
17
|
+
i {
|
|
18
|
+
font-size: 24px;
|
|
19
|
+
margin-top: 4px;
|
|
20
|
+
margin-bottom: 4px;
|
|
21
|
+
color: #4d4d4d;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
label {
|
|
25
|
+
position: absolute;
|
|
26
|
+
top: -17px;
|
|
27
|
+
left: 0;
|
|
28
|
+
font-weight: 500;
|
|
29
|
+
font-size: 12px;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
a {
|
|
33
|
+
text-align: center;
|
|
34
|
+
font-size: 12px;
|
|
35
|
+
margin-top: 2px;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.preview-image-crop {
|
|
39
|
+
height: calc(100% - 24px);
|
|
40
|
+
cursor: pointer;
|
|
41
|
+
|
|
42
|
+
img {
|
|
43
|
+
width: auto;
|
|
44
|
+
height: 100%;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.icon-upload-image-crop {
|
|
49
|
+
width: 100%;
|
|
50
|
+
display: flex;
|
|
51
|
+
flex-direction: column;
|
|
52
|
+
justify-content: center;
|
|
53
|
+
align-items: center;
|
|
54
|
+
|
|
55
|
+
.buttons {
|
|
56
|
+
width: 100%;
|
|
57
|
+
display: flex;
|
|
58
|
+
justify-content: center;
|
|
59
|
+
|
|
60
|
+
a {
|
|
61
|
+
cursor: pointer;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.remove {
|
|
66
|
+
justify-content: space-around;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
&:hover {
|
|
70
|
+
background: #e4e4e4;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
.gap-12 {
|
|
74
|
+
gap: 12px;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import './image-upload-crop.scss'
|
|
2
|
+
import template from './image-upload-crop.html'
|
|
3
|
+
import { IConfigImageUploadCrop } from './interfaces/config-image-upload-crop.interface'
|
|
4
|
+
import { UploadImageCropModal } from './modals/upload-image-crop-modal'
|
|
5
|
+
|
|
6
|
+
class ImageUploadCropController {
|
|
7
|
+
public config: IConfigImageUploadCrop
|
|
8
|
+
public ngModel: string
|
|
9
|
+
|
|
10
|
+
constructor(
|
|
11
|
+
public $scope,
|
|
12
|
+
public $element,
|
|
13
|
+
public $timeout,
|
|
14
|
+
public uploadImageCropModal: UploadImageCropModal,
|
|
15
|
+
) {}
|
|
16
|
+
|
|
17
|
+
$onInit() {
|
|
18
|
+
this.config = this.config || {
|
|
19
|
+
aspectRatio: 1 / 1,
|
|
20
|
+
minCropBoxWidth: 200,
|
|
21
|
+
minCropBoxHeight: 200,
|
|
22
|
+
minCanvasHeight: 100,
|
|
23
|
+
minContainerHeight: 100,
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
removeImage(e) {
|
|
28
|
+
e.stopPropagation()
|
|
29
|
+
this.ngModel = ''
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
openModal() {
|
|
33
|
+
this.uploadImageCropModal.open(this.config, this.ngModel).then((url) => {
|
|
34
|
+
if (url) {
|
|
35
|
+
this.ngModel = url
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const imageUploadCrop = {
|
|
42
|
+
bindings: {
|
|
43
|
+
ngModel: '=?',
|
|
44
|
+
config: '=?',
|
|
45
|
+
},
|
|
46
|
+
controller: ImageUploadCropController,
|
|
47
|
+
template,
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { imageUploadCrop }
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as angular from 'angular'
|
|
2
|
+
import { imageUploadCrop } from './image-upload-crop'
|
|
3
|
+
import { uploadImageCropModalModule } from './modals/upload-image-crop-modal'
|
|
4
|
+
|
|
5
|
+
const mbgImageUploadCropModule = angular
|
|
6
|
+
.module('mbg.components.imageUploadCrop', [uploadImageCropModalModule])
|
|
7
|
+
.component('mbgImageUploadCrop', imageUploadCrop).name
|
|
8
|
+
|
|
9
|
+
export { mbgImageUploadCropModule }
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as angular from 'angular'
|
|
2
|
+
import './upload-image-crop-modal.scss'
|
|
3
|
+
import { UploadImageCropModalController } from './upload-image-crop-modal'
|
|
4
|
+
import UploadImageCropModalTemplate from './upload-image-crop-modal.html'
|
|
5
|
+
import { IConfigImageUploadCrop } from '../../interfaces/config-image-upload-crop.interface'
|
|
6
|
+
|
|
7
|
+
export class UploadImageCropModal {
|
|
8
|
+
constructor(public $uibModal) {}
|
|
9
|
+
|
|
10
|
+
open(cropOptions: IConfigImageUploadCrop, image: string) {
|
|
11
|
+
const modalInstance = this.$uibModal.open({
|
|
12
|
+
template: UploadImageCropModalTemplate,
|
|
13
|
+
controller: UploadImageCropModalController,
|
|
14
|
+
controllerAs: '$ctrl',
|
|
15
|
+
animation: true,
|
|
16
|
+
backdrop: 'static',
|
|
17
|
+
size: 'md',
|
|
18
|
+
resolve: {
|
|
19
|
+
cropOptions: () => cropOptions,
|
|
20
|
+
image: () => image,
|
|
21
|
+
},
|
|
22
|
+
})
|
|
23
|
+
return modalInstance.result
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const uploadImageCropModalModule = angular
|
|
28
|
+
.module(`mbg.modals.uploadImageCropModal`, [])
|
|
29
|
+
.service('uploadImageCropModal', UploadImageCropModal).name
|
|
30
|
+
|
|
31
|
+
export { uploadImageCropModalModule }
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
<div class="upload-image-crop-modal-wrapper">
|
|
2
|
+
<div class="head-logo">
|
|
3
|
+
<h1>Imagem</h1>
|
|
4
|
+
|
|
5
|
+
</div>
|
|
6
|
+
<div class="body-logo">
|
|
7
|
+
<div class="image-container-crop">
|
|
8
|
+
<input type="file"
|
|
9
|
+
multiple="false"
|
|
10
|
+
onchange="angular.element(this).scope().$ctrl.onSelectFiles(event)"
|
|
11
|
+
id="chooseFileLogo" />
|
|
12
|
+
|
|
13
|
+
<div ng-show="!$ctrl.file"
|
|
14
|
+
ng-click="$ctrl.chooseFileLogo()"
|
|
15
|
+
ondrop="angular.element(this).scope().$ctrl.onDropFile(event)"
|
|
16
|
+
ondragover="angular.element(this).scope().$ctrl.onDragOver(event)"
|
|
17
|
+
class="flex flex-column justify-center align-center image-drap-drop-container">
|
|
18
|
+
<div class="flex flex-column align-center justify-center">
|
|
19
|
+
<i ng-show="!$ctrl.image"
|
|
20
|
+
class="fas fa-cloud-upload-alt"></i>
|
|
21
|
+
<label ng-show="$ctrl.image"
|
|
22
|
+
style="font-weight: 500;">Imagem atual</label>
|
|
23
|
+
<img ng-if="$ctrl.image"
|
|
24
|
+
style="max-height: 200px;max-width: 400px; object-fit: contain;"
|
|
25
|
+
class="m-b-24"
|
|
26
|
+
src="{{$ctrl.image}}"></i>
|
|
27
|
+
|
|
28
|
+
<label ng-show="$ctrl.image">Arraste e solte uma imagem ou clique aqui para editar</label>
|
|
29
|
+
<label ng-show="!$ctrl.image">Arraste e solte uma imagem ou clique aqui para adicionar</label>
|
|
30
|
+
</div>
|
|
31
|
+
</div>
|
|
32
|
+
<div class="relative-content"
|
|
33
|
+
ng-if="$ctrl.file">
|
|
34
|
+
<button type="button"
|
|
35
|
+
class="stop-upload"
|
|
36
|
+
ng-click="$ctrl.resetFile()">
|
|
37
|
+
<i class="fas fa-times"></i>
|
|
38
|
+
</button>
|
|
39
|
+
<img ng-src="{{ $ctrl.file }}"
|
|
40
|
+
class="crop-image-original"
|
|
41
|
+
ng-init="$ctrl.createCropier()"
|
|
42
|
+
alt="Logo" />
|
|
43
|
+
</div>
|
|
44
|
+
</div>
|
|
45
|
+
<div class="row"
|
|
46
|
+
ng-show="$ctrl.cropOptions.recommendedWidth && $ctrl.cropOptions.recommendedHeight">
|
|
47
|
+
<div class="col-md-12">
|
|
48
|
+
<p style="margin-bottom: 0px">Tamanho recomendado em pixels: ({{$ctrl.cropOptions.recommendedWidth}} x
|
|
49
|
+
{{$ctrl.cropOptions.recommendedHeight}})px
|
|
50
|
+
</p>
|
|
51
|
+
</div>
|
|
52
|
+
</div>
|
|
53
|
+
<div class="row m-t-24">
|
|
54
|
+
<div class="col-md-12 flex flex-column align-center justify-center">
|
|
55
|
+
<mbg-btn-form ng-click="$ctrl.save()"
|
|
56
|
+
ng-disabled="$ctrl.loading"
|
|
57
|
+
loading="$ctrl.loading"
|
|
58
|
+
label="Confirmar"></mbg-btn-form>
|
|
59
|
+
<label class="error-label"
|
|
60
|
+
ng-class="{'active': $ctrl.activeError}">{{$ctrl.labelError}}</label>
|
|
61
|
+
<div class="flex align-center">
|
|
62
|
+
<a class="cancel-link"
|
|
63
|
+
target="_self"
|
|
64
|
+
ng-disabled="$ctrl.loading"
|
|
65
|
+
ng-click="$ctrl.closeModal()">Cancelar</a>
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
68
|
+
</div>
|
|
69
|
+
|
|
70
|
+
</div>
|
|
71
|
+
</div>
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
.upload-image-crop-modal-wrapper {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
width: 100%;
|
|
5
|
+
|
|
6
|
+
.relative-content {
|
|
7
|
+
position: relative;
|
|
8
|
+
max-height: 400px;
|
|
9
|
+
|
|
10
|
+
.stop-upload {
|
|
11
|
+
z-index: 1000;
|
|
12
|
+
position: absolute;
|
|
13
|
+
top: 4px;
|
|
14
|
+
right: 4px;
|
|
15
|
+
background: #fff;
|
|
16
|
+
border-radius: 50%;
|
|
17
|
+
font-size: 21px;
|
|
18
|
+
width: 34px;
|
|
19
|
+
height: 34px;
|
|
20
|
+
border: 2px solid #595959;
|
|
21
|
+
color: #666;
|
|
22
|
+
transform: scale(0.8);
|
|
23
|
+
transition: all 300ms ease;
|
|
24
|
+
|
|
25
|
+
&:hover {
|
|
26
|
+
transform: scale(0.9);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.cropper-container {
|
|
32
|
+
width: 100% !important;
|
|
33
|
+
height: 368px !important;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.head-logo {
|
|
37
|
+
padding: 0 24px;
|
|
38
|
+
h1 {
|
|
39
|
+
color: var(--neutral1);
|
|
40
|
+
font-size: 24px;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
.body-logo {
|
|
44
|
+
flex: 1;
|
|
45
|
+
position: relative;
|
|
46
|
+
padding: 0 24px;
|
|
47
|
+
padding-bottom: 24px;
|
|
48
|
+
}
|
|
49
|
+
.image-container-crop {
|
|
50
|
+
width: 100%;
|
|
51
|
+
background: #f5f5f5;
|
|
52
|
+
height: 368px;
|
|
53
|
+
border-radius: 5px;
|
|
54
|
+
overflow: hidden;
|
|
55
|
+
cursor: pointer;
|
|
56
|
+
}
|
|
57
|
+
#chooseFileLogo {
|
|
58
|
+
display: none;
|
|
59
|
+
}
|
|
60
|
+
.crop-image-original {
|
|
61
|
+
display: block;
|
|
62
|
+
max-width: 100%;
|
|
63
|
+
}
|
|
64
|
+
.image-drap-drop-container {
|
|
65
|
+
height: 100%;
|
|
66
|
+
|
|
67
|
+
i {
|
|
68
|
+
font-size: 68px;
|
|
69
|
+
color: #666;
|
|
70
|
+
}
|
|
71
|
+
label {
|
|
72
|
+
font-size: 16px;
|
|
73
|
+
margin: 14px 4px;
|
|
74
|
+
cursor: pointer;
|
|
75
|
+
}
|
|
76
|
+
button {
|
|
77
|
+
margin-top: 18px;
|
|
78
|
+
height: 44px;
|
|
79
|
+
padding: 0 24px;
|
|
80
|
+
border-radius: 41px;
|
|
81
|
+
background: var(--contrast);
|
|
82
|
+
color: #fff;
|
|
83
|
+
border: none;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.flex {
|
|
88
|
+
display: flex;
|
|
89
|
+
.flex-1 {
|
|
90
|
+
flex: 1;
|
|
91
|
+
}
|
|
92
|
+
.fit-content {
|
|
93
|
+
min-height: fit-content;
|
|
94
|
+
}
|
|
95
|
+
&.flex-row {
|
|
96
|
+
flex-direction: row;
|
|
97
|
+
}
|
|
98
|
+
&.flex-column {
|
|
99
|
+
flex-direction: column;
|
|
100
|
+
}
|
|
101
|
+
&.align-center {
|
|
102
|
+
align-items: center;
|
|
103
|
+
}
|
|
104
|
+
&.align-end {
|
|
105
|
+
align-items: flex-end;
|
|
106
|
+
}
|
|
107
|
+
&.align-start {
|
|
108
|
+
align-items: flex-start;
|
|
109
|
+
}
|
|
110
|
+
&.align-between {
|
|
111
|
+
align-items: space-between;
|
|
112
|
+
}
|
|
113
|
+
&.justify-center {
|
|
114
|
+
justify-content: center;
|
|
115
|
+
}
|
|
116
|
+
&.justify-end {
|
|
117
|
+
justify-content: flex-end;
|
|
118
|
+
}
|
|
119
|
+
&.justify-start {
|
|
120
|
+
justify-content: flex-start;
|
|
121
|
+
}
|
|
122
|
+
&.justify-between {
|
|
123
|
+
justify-content: space-between;
|
|
124
|
+
}
|
|
125
|
+
&.justify-around {
|
|
126
|
+
justify-content: space-around;
|
|
127
|
+
}
|
|
128
|
+
&.wrap {
|
|
129
|
+
flex-wrap: wrap;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
.m-t-24 {
|
|
133
|
+
margin-top: 24px;
|
|
134
|
+
}
|
|
135
|
+
.cancel-link {
|
|
136
|
+
margin: 18px 24px 0px 24px;
|
|
137
|
+
color: var(--neutral2);
|
|
138
|
+
cursor: pointer;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// import { MobiEVendiService } from 'modules/mobi-store/services/mobi-e-vendi-service'
|
|
2
|
+
import 'cropperjs/dist/cropper.css'
|
|
3
|
+
// import Cropper from 'cropperjs'
|
|
4
|
+
import Cropper from 'cropperjs/dist/cropper.esm'
|
|
5
|
+
import { UtilMbgFunctions } from '../../../../helpers/util-mbg-functions'
|
|
6
|
+
import { UtilUID } from '../../../../helpers/util-uid'
|
|
7
|
+
import { MbgImageUploadService } from '../../../mbg-image-upload/services/mbg-image-upload-service'
|
|
8
|
+
import firebase from 'firebase/app'
|
|
9
|
+
import 'firebase/storage'
|
|
10
|
+
// import { UtilUID } from 'modules/helpers/namespaces/util-uid'
|
|
11
|
+
// import { SessionStorage } from 'modules/helpers/namespaces/sessionstorage'
|
|
12
|
+
// import { HelperNotificationService } from 'modules/helpers/services/notification.service'
|
|
13
|
+
|
|
14
|
+
class UploadImageCropModalController {
|
|
15
|
+
private file
|
|
16
|
+
private cropper: Cropper
|
|
17
|
+
private loading
|
|
18
|
+
private activeError: boolean
|
|
19
|
+
private labelError: string
|
|
20
|
+
|
|
21
|
+
constructor(
|
|
22
|
+
public $timeout,
|
|
23
|
+
public $scope,
|
|
24
|
+
public $uibModalInstance,
|
|
25
|
+
public cropOptions,
|
|
26
|
+
public image,
|
|
27
|
+
public mbgImageUploadService: MbgImageUploadService,
|
|
28
|
+
) {}
|
|
29
|
+
|
|
30
|
+
$onInit() {
|
|
31
|
+
this.$scope.$on('$destroy', () => {
|
|
32
|
+
this.destroyCropier()
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
closeModal() {
|
|
37
|
+
this.$uibModalInstance.close()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async onFileSelect(file) {
|
|
41
|
+
const base64 = await this.toBase64(file)
|
|
42
|
+
this.$timeout(() => {
|
|
43
|
+
this.file = base64
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
createCropier() {
|
|
48
|
+
this.$timeout(() => {
|
|
49
|
+
const image: any = document.querySelector('.crop-image-original')
|
|
50
|
+
this.cropper = new Cropper(
|
|
51
|
+
image,
|
|
52
|
+
Object.assign(
|
|
53
|
+
{
|
|
54
|
+
dragMode: 'move',
|
|
55
|
+
},
|
|
56
|
+
this.cropOptions,
|
|
57
|
+
),
|
|
58
|
+
)
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
toBase64 = (file) => {
|
|
63
|
+
return new Promise((resolve, reject) => {
|
|
64
|
+
const reader = new FileReader()
|
|
65
|
+
reader.readAsDataURL(file)
|
|
66
|
+
reader.onload = () => resolve(reader.result)
|
|
67
|
+
reader.onerror = (error) => reject(error)
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
onDropFile(ev) {
|
|
72
|
+
ev.preventDefault()
|
|
73
|
+
const dataTransfer = ev.dataTransfer
|
|
74
|
+
if (dataTransfer.files && dataTransfer.files.length > 0) {
|
|
75
|
+
const file = dataTransfer.files[0]
|
|
76
|
+
this.onFileSelect(file)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
onDragOver(ev) {
|
|
81
|
+
ev.preventDefault()
|
|
82
|
+
ev.dataTransfer.dropEffect = 'move'
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
chooseFileLogo() {
|
|
86
|
+
const input: any = document.querySelector('#chooseFileLogo')
|
|
87
|
+
input.value = ''
|
|
88
|
+
input.click()
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
resetFile() {
|
|
92
|
+
this.file = null
|
|
93
|
+
const input: any = document.querySelector('#chooseFileLogo')
|
|
94
|
+
input.value = ''
|
|
95
|
+
this.destroyCropier()
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
onSelectFiles(ev) {
|
|
99
|
+
const files = ev.target.files
|
|
100
|
+
if (files && files.length > 0) {
|
|
101
|
+
this.onFileSelect(files[0])
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
destroyCropier() {
|
|
106
|
+
if (this.cropper) {
|
|
107
|
+
this.cropper.destroy()
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
dismiss() {
|
|
112
|
+
this.$uibModalInstance.close(false)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async save() {
|
|
116
|
+
try {
|
|
117
|
+
this.loading = true
|
|
118
|
+
this.activeError = false
|
|
119
|
+
const URL_FIREBASE = 'https://firebasestorage.googleapis.com/v0/b/bucket/o/id?alt=media'
|
|
120
|
+
const base64 = this.cropper.getCroppedCanvas().toDataURL()
|
|
121
|
+
const imageID = UtilUID.generete()
|
|
122
|
+
|
|
123
|
+
const storageRef = (window['firebase'] ? window['firebase'].storage() : firebase.storage())
|
|
124
|
+
.ref()
|
|
125
|
+
.child(imageID)
|
|
126
|
+
const response = await storageRef.putString(base64, 'data_url')
|
|
127
|
+
const imageURL = URL_FIREBASE.replace(/bucket/g, response.metadata.bucket).replace(
|
|
128
|
+
/id/g,
|
|
129
|
+
response.metadata.name,
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
this.$uibModalInstance.close(imageURL)
|
|
133
|
+
} catch (e) {
|
|
134
|
+
console.log(e)
|
|
135
|
+
this.loading = false
|
|
136
|
+
this.activeError = true
|
|
137
|
+
this.labelError = 'Erro ao salvar a imagem, tente novamente!'
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
UploadImageCropModalController[`$inject`] = [
|
|
143
|
+
'$timeout',
|
|
144
|
+
'$scope',
|
|
145
|
+
'$uibModalInstance',
|
|
146
|
+
'cropOptions',
|
|
147
|
+
'image',
|
|
148
|
+
'mbgImageUploadService',
|
|
149
|
+
]
|
|
150
|
+
|
|
151
|
+
export { UploadImageCropModalController }
|
package/src/index.html
CHANGED
|
@@ -982,7 +982,8 @@
|
|
|
982
982
|
{{teste}}
|
|
983
983
|
</div> -->
|
|
984
984
|
<div style="padding: 100px">
|
|
985
|
-
|
|
985
|
+
|
|
986
|
+
<!-- <div class="panel panel-default">
|
|
986
987
|
<div class="panel-heading">Ace Editor</div>
|
|
987
988
|
<div class="panel-body">
|
|
988
989
|
<mbg-ace-editor ng-model="aceEditor"
|
|
@@ -999,8 +1000,14 @@
|
|
|
999
1000
|
<mbg-input-text ng-model="asdasdasd"
|
|
1000
1001
|
ng-change="hhhsss($event)"></mbg-input-text>
|
|
1001
1002
|
</div>
|
|
1003
|
+
</div> -->
|
|
1004
|
+
|
|
1005
|
+
<div>
|
|
1006
|
+
<mbg-image-upload-crop ng-model="imgCrop"
|
|
1007
|
+
config="configImgCrop"></mbg-image-upload-crop>
|
|
1002
1008
|
</div>
|
|
1003
1009
|
|
|
1010
|
+
|
|
1004
1011
|
</div>
|
|
1005
1012
|
</body>
|
|
1006
1013
|
|
package/src/index.ts
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
import * as angular from 'angular'
|
|
4
4
|
import components from './components'
|
|
5
|
-
import
|
|
5
|
+
import * as firebase from 'firebase'
|
|
6
|
+
import 'firebase/firestore'
|
|
6
7
|
import './assets/angular-locale_pt-br.js'
|
|
7
8
|
import * as dataDocument from './assets/data-default.json'
|
|
8
9
|
import { MbgAlert } from './helpers/services/mbg-alert'
|
|
@@ -13,7 +14,7 @@ const sizeJson = require('./json/sizes.json')
|
|
|
13
14
|
const genderJson = require('./json/gender.json')
|
|
14
15
|
const mockData = require('./json/MOCK_DATA.json')
|
|
15
16
|
|
|
16
|
-
initializeApp({
|
|
17
|
+
firebase.initializeApp({
|
|
17
18
|
apiKey: 'AIzaSyB0aH7e6XjWJ-xViji3CuXHBbLuWRALC78',
|
|
18
19
|
authDomain: 'app-kigi.firebaseapp.com',
|
|
19
20
|
databaseURL: 'https://app-kigi-default-rtdb.firebaseio.com',
|
|
@@ -30,6 +31,17 @@ const module = angular.module('demo', ['ngLocale', components]).controller('demo
|
|
|
30
31
|
'$http',
|
|
31
32
|
'mbgAlert',
|
|
32
33
|
($scope, $timeout, $http, mbgAlert: MbgAlert) => {
|
|
34
|
+
$scope.imgCrop = 'https://i.pinimg.com/originals/c3/a5/b3/c3a5b332f9716abb1c67da38a12595e8.jpg'
|
|
35
|
+
$scope.configImgCrop = {
|
|
36
|
+
aspectRatio: 16 / 9,
|
|
37
|
+
minCropBoxWidth: 200,
|
|
38
|
+
minCropBoxHeight: 100,
|
|
39
|
+
minCanvasHeight: 200,
|
|
40
|
+
minContainerHeight: 100,
|
|
41
|
+
height: '124px',
|
|
42
|
+
// width: '300px',
|
|
43
|
+
}
|
|
44
|
+
|
|
33
45
|
$scope.configDocument = {
|
|
34
46
|
document: dataDocument,
|
|
35
47
|
preview: true,
|