@kigi/components 1.5.9 → 1.5.10-beta.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kigi/components",
3
- "version": "1.5.9",
3
+ "version": "1.5.10-beta.0",
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": "^7.16.0",
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",
@@ -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
- const URL_FIREBASE = 'https://firebasestorage.googleapis.com/v0/b/bucket/o/id?alt=media'
5
+ const URL_FIREBASE = 'https://firebasestorage.googleapis.com/v0/b/bucket/o/id?alt=media'
6
6
 
7
- export function getStorage(): any {
8
- return window['firebase'] ? window['firebase'].storage() : firebase.storage()
9
- }
7
+ export function getStorage(): any {
8
+ return window['firebase'] ? window['firebase'].storage() : firebase.storage()
9
+ }
10
10
 
11
- export function guid() {
12
- const s4 = () => Math.floor((1 + Math.random()) * 0x10000)
13
- .toString(16)
14
- .substring(1)
15
- return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4()
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
- export async function removeFiles(files) {
19
- files.forEach((file) => {
20
- if (file) {
21
- const storageRef = getStorage().ref().child(file.idStorage)
22
- storageRef.delete()
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
- export async function upload(files: Array<string>, folder = '') {
28
- return await Promise.all(files.map(async (base64) => {
29
- const imageID = this.guid()
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().ref().child(folder ? `${folder}/${imageID}` : imageID)
41
- const uploadTask = storageRef.put(file)
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
- uploadTask.on('state_changed', (snapshot) => {
44
- const progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100
45
- config.onProgress(progress)
46
- switch (snapshot.state) {
47
- case firebase.storage.TaskState.PAUSED:
48
- config.onPause()
49
- break
50
- case firebase.storage.TaskState.RUNNING:
51
- config.onResume()
52
- break
53
- }
54
- }, (e) => {
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
- uploadTask.snapshot.ref.getDownloadURL()
58
- .then((downloadURL) => {
59
- config.onSuccess({ fileName: file.name, fileURL: downloadURL, fileSize: file.size })
60
- })
61
- .catch(() => {
62
- config.onError()
63
- })
64
- })
65
- return uploadTask
66
- }
86
+ })
87
+ },
88
+ )
89
+ return uploadTask
90
+ }
67
91
  }
@@ -0,0 +1,23 @@
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
+ src="{{$ctrl.ngModel}}">
11
+ </div>
12
+ <div class="icon-upload-image-crop">
13
+ <i ng-show="!$ctrl.ngModel"
14
+ class="fas fa-cloud-upload-alt"></i>
15
+ <div class="buttons"
16
+ ng-class="{'remove': $ctrl.ngModel}">
17
+ <a ng-click="$ctrl.removeImage($event)">{{$ctrl.ngModel ? 'Remover' : ''}}</a>
18
+ <a ng-click="$ctrl.openModal()">{{$ctrl.ngModel ? 'Alterar' : 'Fazer upload'}}</a>
19
+ </div>
20
+ </div>
21
+
22
+ </div>
23
+ </div>
@@ -0,0 +1,74 @@
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
+ cursor: pointer;
57
+ width: 100%;
58
+ display: flex;
59
+ justify-content: center;
60
+ }
61
+
62
+ .remove {
63
+ justify-content: space-around;
64
+ }
65
+ }
66
+
67
+ &:hover {
68
+ background: #e4e4e4;
69
+ }
70
+ }
71
+ .gap-12 {
72
+ gap: 12px;
73
+ }
74
+ }
@@ -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,9 @@
1
+ export interface IConfigImageUploadCrop {
2
+ aspectRatio: number
3
+ minCropBoxWidth: number
4
+ minCropBoxHeight: number
5
+ minCanvasHeight: number
6
+ minContainerHeight: number
7
+ width?: string
8
+ height?: string
9
+ }
@@ -0,0 +1,32 @@
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
+ windowClass: 'reward-e-vendi-modal',
18
+ size: 'md',
19
+ resolve: {
20
+ cropOptions: () => cropOptions,
21
+ image: () => image,
22
+ },
23
+ })
24
+ return modalInstance.result
25
+ }
26
+ }
27
+
28
+ const uploadImageCropModalModule = angular
29
+ .module(`mbg.modals.uploadImageCropModal`, [])
30
+ .service('uploadImageCropModal', UploadImageCropModal).name
31
+
32
+ export { uploadImageCropModalModule }
@@ -0,0 +1,70 @@
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="width: 50%;"
25
+ class="m-b-24"
26
+ src="{{$ctrl.image}}"></i>
27
+
28
+ <label ng-show="$ctrl.image">Clique aqui ou arraste e solte uma imagem para editar</label>
29
+ <label ng-show="!$ctrl.image">Clique aqui ou arraste e solte uma imagem 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
+ <div class="col-md-12">
47
+ <p style="margin-bottom: 0px">Tamanho ideal em pixels: ({{$ctrl.cropOptions.minCropBoxWidth}} x
48
+ {{$ctrl.cropOptions.minCropBoxHeight}})px
49
+ </p>
50
+ </div>
51
+ </div>
52
+ <div class="row m-t-24">
53
+ <div class="col-md-12 flex flex-column align-center justify-center">
54
+ <mbg-btn-form ng-click="$ctrl.save()"
55
+ ng-disabled="$ctrl.loading"
56
+ loading="$ctrl.loading"
57
+ label="Confirmar"></mbg-btn-form>
58
+ <label class="error-label"
59
+ ng-class="{'active': $ctrl.activeError}">{{$ctrl.labelError}}</label>
60
+ <div class="flex align-center">
61
+ <a class="cancel-link"
62
+ target="_self"
63
+ ng-disabled="$ctrl.loading"
64
+ ng-click="$ctrl.closeModal()">Cancelar</a>
65
+ </div>
66
+ </div>
67
+ </div>
68
+
69
+ </div>
70
+ </div>
@@ -0,0 +1,138 @@
1
+ .upload-image-crop-modal-wrapper {
2
+ display: flex;
3
+ flex-direction: column;
4
+ width: 100%;
5
+
6
+ .relative-content {
7
+ position: relative;
8
+
9
+ .stop-upload {
10
+ z-index: 1000;
11
+ position: absolute;
12
+ top: 4px;
13
+ right: 4px;
14
+ background: #fff;
15
+ border-radius: 50%;
16
+ font-size: 21px;
17
+ width: 34px;
18
+ height: 34px;
19
+ border: 2px solid #595959;
20
+ color: #666;
21
+ transform: scale(0.8);
22
+ transition: all 300ms ease;
23
+
24
+ &:hover {
25
+ transform: scale(0.9);
26
+ }
27
+ }
28
+ }
29
+
30
+ .cropper-container {
31
+ width: 100% !important;
32
+ height: 368px !important;
33
+ }
34
+
35
+ .head-logo {
36
+ padding: 0 24px;
37
+ h1 {
38
+ color: var(--neutral1);
39
+ font-size: 24px;
40
+ }
41
+ }
42
+ .body-logo {
43
+ flex: 1;
44
+ position: relative;
45
+ padding: 0 24px;
46
+ padding-bottom: 24px;
47
+ }
48
+ .image-container-crop {
49
+ width: 100%;
50
+ background: #f5f5f5;
51
+ height: 368px;
52
+ border-radius: 5px;
53
+ overflow: hidden;
54
+ cursor: pointer;
55
+ }
56
+ #chooseFileLogo {
57
+ display: none;
58
+ }
59
+ .crop-image-original {
60
+ max-width: 100%;
61
+ }
62
+ .image-drap-drop-container {
63
+ height: 100%;
64
+
65
+ i {
66
+ font-size: 68px;
67
+ color: #666;
68
+ }
69
+ label {
70
+ font-size: 16px;
71
+ margin: 14px 4px;
72
+ cursor: pointer;
73
+ }
74
+ button {
75
+ margin-top: 18px;
76
+ height: 44px;
77
+ padding: 0 24px;
78
+ border-radius: 41px;
79
+ background: var(--contrast);
80
+ color: #fff;
81
+ border: none;
82
+ }
83
+ }
84
+
85
+ .flex {
86
+ display: flex;
87
+ .flex-1 {
88
+ flex: 1;
89
+ }
90
+ .fit-content {
91
+ min-height: fit-content;
92
+ }
93
+ &.flex-row {
94
+ flex-direction: row;
95
+ }
96
+ &.flex-column {
97
+ flex-direction: column;
98
+ }
99
+ &.align-center {
100
+ align-items: center;
101
+ }
102
+ &.align-end {
103
+ align-items: flex-end;
104
+ }
105
+ &.align-start {
106
+ align-items: flex-start;
107
+ }
108
+ &.align-between {
109
+ align-items: space-between;
110
+ }
111
+ &.justify-center {
112
+ justify-content: center;
113
+ }
114
+ &.justify-end {
115
+ justify-content: flex-end;
116
+ }
117
+ &.justify-start {
118
+ justify-content: flex-start;
119
+ }
120
+ &.justify-between {
121
+ justify-content: space-between;
122
+ }
123
+ &.justify-around {
124
+ justify-content: space-around;
125
+ }
126
+ &.wrap {
127
+ flex-wrap: wrap;
128
+ }
129
+ }
130
+ .m-t-24 {
131
+ margin-top: 24px;
132
+ }
133
+ .cancel-link {
134
+ margin: 18px 24px 0px 24px;
135
+ color: var(--neutral2);
136
+ cursor: pointer;
137
+ }
138
+ }
@@ -0,0 +1,152 @@
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
+ console.log(imageURL)
133
+ this.$uibModalInstance.close(imageURL)
134
+ } catch (e) {
135
+ console.log(e)
136
+ this.loading = false
137
+ this.activeError = true
138
+ this.labelError = 'Erro ao salvar a imagem, tente novamente!'
139
+ }
140
+ }
141
+ }
142
+
143
+ UploadImageCropModalController[`$inject`] = [
144
+ '$timeout',
145
+ '$scope',
146
+ '$uibModalInstance',
147
+ 'cropOptions',
148
+ 'image',
149
+ 'mbgImageUploadService',
150
+ ]
151
+
152
+ export { UploadImageCropModalController }
@@ -5,157 +5,169 @@ import * as Fuse from 'fuse.js'
5
5
  import { UtilUID } from '../../helpers/util-uid'
6
6
 
7
7
  export class MbgSelectMultiListController {
8
- private data: Array<any>
9
- private ngModel: any
10
- private dataModel: Array<any>
11
- private fetch: Function
12
- private label: string
13
- private isLoading: boolean
14
- private inputValue: string
15
- private listRowTransclude: string
16
- private listHeaderTransclude: string
17
- private placeholderLeft: string
18
- private placeholderRight: string
19
- private inputValueResult: string
20
-
21
- constructor(public $scope, public $element, public $attrs, public $timeout, public $compile, public $transclude) { }
22
-
23
- $onInit() {
24
- this.placeholderLeft = this.placeholderLeft || ''
25
- this.placeholderRight = this.placeholderRight || ''
26
- this.$scope.$c = this.$scope.$parent
27
- this.findTransclude()
28
- this.findTranscludeHeader()
29
- this.$scope.$watch('$ctrl.data', (data) => {
30
- this.afterFetchData(data)
31
- }, true)
32
- this.$timeout(() => {
33
- this.ngModel = this.ngModel || []
34
- this.dataModel = JSON.parse(JSON.stringify(this.ngModel)) || []
35
- })
36
- }
37
-
38
- findTransclude() {
39
- this.$transclude(this.$scope, (cloneEl) => {
40
- angular.forEach(cloneEl, cl => {
41
- let element = angular.element(cl)[0]
42
- if (element.nodeName && element.nodeName === 'MBG-ROW-CONTENT') {
43
- this.listRowTransclude = element.innerHTML
44
- }
45
- })
46
- })
47
- }
48
-
49
- findTranscludeHeader() {
50
- this.$transclude(this.$scope, (cloneEl) => {
51
- angular.forEach(cloneEl, cl => {
52
- let element = angular.element(cl)[0]
53
- if (element.nodeName && element.nodeName === 'MBG-HEADER-CONTENT') {
54
- this.listHeaderTransclude = element.innerHTML
55
- }
56
- })
57
- })
58
- }
59
-
60
- executeFetch() {
61
- this.$timeout(() => {
62
- this.fetch({ query: (this.inputValue || '') })
63
- })
64
- }
65
-
66
- afterFetchData(data) {
67
- this.$timeout(() => {
68
- this.data = (data || []).filter((row) => this.ngModel.filter((model) => angular.equals(row, model)).length === 0)
69
- })
70
- }
71
-
72
- selectRow(row) {
73
- const copyRow = JSON.parse(JSON.stringify(row))
74
- const index = this.findIndexRow(this.data, row)
75
- if (index !== -1) {
76
- copyRow._uid = UtilUID.generete()
77
- this.ngModel.push(copyRow)
78
- this.dataModel.push(copyRow)
79
- this.data.splice(index, 1)
80
- this.$timeout(() => {
81
- (this.ngModel || []).forEach((model) => {
82
- delete model._uid
83
- })
84
- }, 500)
8
+ private data: Array<any>
9
+ private ngModel: any
10
+ private dataModel: Array<any>
11
+ private fetch: Function
12
+ private label: string
13
+ private isLoading: boolean
14
+ private inputValue: string
15
+ private listRowTransclude: string
16
+ private listHeaderTransclude: string
17
+ private placeholderLeft: string
18
+ private placeholderRight: string
19
+ private inputValueResult: string
20
+
21
+ constructor(
22
+ public $scope,
23
+ public $element,
24
+ public $attrs,
25
+ public $timeout,
26
+ public $compile,
27
+ public $transclude,
28
+ ) {}
29
+
30
+ $onInit() {
31
+ this.placeholderLeft = this.placeholderLeft || ''
32
+ this.placeholderRight = this.placeholderRight || ''
33
+ this.$scope.$c = this.$scope.$parent
34
+ this.findTransclude()
35
+ this.findTranscludeHeader()
36
+ this.$scope.$watch(
37
+ '$ctrl.data',
38
+ (data) => {
39
+ this.afterFetchData(data)
40
+ },
41
+ true,
42
+ )
43
+ this.$timeout(() => {
44
+ this.ngModel = this.ngModel || []
45
+ this.dataModel = JSON.parse(JSON.stringify(this.ngModel)) || []
46
+ })
47
+ }
48
+
49
+ findTransclude() {
50
+ this.$transclude(this.$scope, (cloneEl) => {
51
+ angular.forEach(cloneEl, (cl) => {
52
+ let element = angular.element(cl)[0]
53
+ if (element.nodeName && element.nodeName === 'MBG-ROW-CONTENT') {
54
+ this.listRowTransclude = element.innerHTML
85
55
  }
86
- }
87
-
88
- removeRow(row) {
89
- this.$timeout(() => {
90
- const index = this.findIndexRow(this.ngModel, row)
91
- const indexData = this.findIndexRow(this.dataModel, row)
92
- if (index !== -1) {
93
- this.ngModel.splice(index, 1)
94
- this.dataModel.splice(indexData, 1)
95
- this.executeFetch()
96
- }
97
- })
98
- }
99
-
100
- searchNgModel() {
101
- this.$timeout(() => {
102
- const dataModel = JSON.parse(JSON.stringify(this.ngModel))
103
- const options = {
104
- shouldSort: true,
105
- threshold: 0.3,
106
- location: 0,
107
- distance: 100,
108
- maxPatternLength: 32,
109
- minMatchCharLength: 1,
110
- keys: [this.label]
111
- }
112
- const fuse = new Fuse(dataModel, options)
113
- const result = fuse.search(this.inputValueResult)
114
- this.dataModel = result.length > 0 ? result : dataModel
56
+ })
57
+ })
58
+ }
59
+
60
+ findTranscludeHeader() {
61
+ this.$transclude(this.$scope, (cloneEl) => {
62
+ angular.forEach(cloneEl, (cl) => {
63
+ let element = angular.element(cl)[0]
64
+ if (element.nodeName && element.nodeName === 'MBG-HEADER-CONTENT') {
65
+ this.listHeaderTransclude = element.innerHTML
66
+ }
67
+ })
68
+ })
69
+ }
70
+
71
+ executeFetch() {
72
+ this.$timeout(() => {
73
+ this.fetch({ query: this.inputValue || '' })
74
+ })
75
+ }
76
+
77
+ afterFetchData(data) {
78
+ this.$timeout(() => {
79
+ this.data = (data || []).filter(
80
+ (row) => this.ngModel.filter((model) => angular.equals(row, model)).length === 0,
81
+ )
82
+ })
83
+ }
84
+
85
+ selectRow(row) {
86
+ const copyRow = JSON.parse(JSON.stringify(row))
87
+ const index = this.findIndexRow(this.data, row)
88
+ if (index !== -1) {
89
+ copyRow._uid = UtilUID.generete()
90
+ this.ngModel.push(copyRow)
91
+ this.dataModel.push(copyRow)
92
+ this.data.splice(index, 1)
93
+ this.$timeout(() => {
94
+ ;(this.ngModel || []).forEach((model) => {
95
+ delete model._uid
115
96
  })
116
-
117
- }
118
-
119
- findIndexRow(array: Array<any>, row) {
120
- return array.findIndex((data) => angular.equals(data, row))
121
- }
122
-
123
- async addEvent(row) {
124
- const target: any = angular.element('.result-multi-list-wrapper')
125
- await target.animate({ scrollTop: this.dataModel.length * 44 }, 500)
126
- this.$timeout(() => {
127
- const element = angular.element(`div[id="${row['_uid']}"]`)
128
- element.addClass('active')
129
- this.$timeout(() => element.removeClass('active'), 300)
130
- }, 100)
97
+ }, 500)
131
98
  }
99
+ }
100
+
101
+ removeRow(row) {
102
+ this.$timeout(() => {
103
+ const index = this.findIndexRow(this.ngModel, row)
104
+ const indexData = this.findIndexRow(this.dataModel, row)
105
+ if (index !== -1) {
106
+ this.ngModel.splice(index, 1)
107
+ this.dataModel.splice(indexData, 1)
108
+ this.executeFetch()
109
+ }
110
+ })
111
+ }
112
+
113
+ searchNgModel() {
114
+ this.$timeout(() => {
115
+ const dataModel = JSON.parse(JSON.stringify(this.ngModel))
116
+ const options = {
117
+ shouldSort: true,
118
+ threshold: 0.3,
119
+ location: 0,
120
+ distance: 100,
121
+ maxPatternLength: 32,
122
+ minMatchCharLength: 1,
123
+ keys: [this.label],
124
+ }
125
+ const fuse = new Fuse(dataModel, options)
126
+ const result = fuse.search(this.inputValueResult)
127
+ this.dataModel = result.length > 0 ? result : dataModel
128
+ })
129
+ }
130
+
131
+ findIndexRow(array: Array<any>, row) {
132
+ return array.findIndex((data) => angular.equals(data, row))
133
+ }
134
+
135
+ async addEvent(row) {
136
+ const target: any = angular.element('.result-multi-list-wrapper')
137
+ await target.animate({ scrollTop: this.dataModel.length * 44 }, 500)
138
+ this.$timeout(() => {
139
+ const element = angular.element(`div[id="${row['_uid']}"]`)
140
+ element.addClass('active')
141
+ this.$timeout(() => element.removeClass('active'), 300)
142
+ }, 100)
143
+ }
132
144
  }
133
145
 
134
146
  MbgSelectMultiListController.$inject = [
135
- '$scope',
136
- '$element',
137
- '$attrs',
138
- '$timeout',
139
- '$compile',
140
- '$transclude'
147
+ '$scope',
148
+ '$element',
149
+ '$attrs',
150
+ '$timeout',
151
+ '$compile',
152
+ '$transclude',
141
153
  ]
142
154
 
143
155
  const mbgSelectMultiList = {
144
- transclude: true,
145
- bindings: {
146
- ngModel: '=?',
147
- fetch: '&?',
148
- label: '@?',
149
- count: '=?',
150
- placeholderLeft: '@?',
151
- placeholderRight: '@?',
152
- titleLeft: '@?',
153
- titleRight: '@?',
154
- data: '=?',
155
- isLoading: '=?'
156
- },
157
- template,
158
- controller: MbgSelectMultiListController,
156
+ transclude: true,
157
+ bindings: {
158
+ ngModel: '=?',
159
+ fetch: '&?',
160
+ label: '@?',
161
+ count: '=?',
162
+ placeholderLeft: '@?',
163
+ placeholderRight: '@?',
164
+ titleLeft: '@?',
165
+ titleRight: '@?',
166
+ data: '=?',
167
+ isLoading: '=?',
168
+ },
169
+ template,
170
+ controller: MbgSelectMultiListController,
159
171
  }
160
172
 
161
173
  export { mbgSelectMultiList }
@@ -1,14 +1,15 @@
1
1
  <div class="mbg-text-wrapper mb-text-area-wrapper">
2
2
  <textarea type="text"
3
- ng-model="$ctrl.ngModel"
4
- ng-change="$ctrl.onChange()"
5
- ng-required="$ctrl.ngRequired"
6
- ng-disabled="$ctrl.ngDisabled"
7
- ng-blur="$ctrl.ngBlur({ $event })"
8
- ng-focus="$ctrl.ngFocus({ $event })"
9
- ng-keyup="$ctrl.ngKeyup({ $event })"
10
- ng-keypress="$ctrl.ngKeypress({ $event })"
11
- ng-keydown="$ctrl.ngKeydown({ $event })"
12
- placeholder="{{ $ctrl.placeholder }}" >
3
+ ng-model="$ctrl.ngModel"
4
+ ng-change="$ctrl.onChange()"
5
+ ng-required="$ctrl.ngRequired"
6
+ ng-disabled="$ctrl.ngDisabled"
7
+ ng-blur="$ctrl.ngBlur({ $event })"
8
+ ng-focus="$ctrl.ngFocus({ $event })"
9
+ ng-keyup="$ctrl.ngKeyup({ $event })"
10
+ ng-keypress="$ctrl.ngKeypress({ $event })"
11
+ ng-keydown="$ctrl.ngKeydown({ $event })"
12
+ placeholder="{{ $ctrl.placeholder }}"
13
+ maxlength="{{$ctrl.maxLength}}">
13
14
  </textarea>
14
15
  </div>
@@ -36,6 +36,7 @@ const mbgTextArea = {
36
36
  ngKeypress: '&?',
37
37
  ngKeydown: '&?',
38
38
  placeholder: '@?',
39
+ maxLength: '@?',
39
40
  },
40
41
  template,
41
42
  controller: MbgTextAreaController,
package/src/index.html CHANGED
@@ -982,7 +982,8 @@
982
982
  {{teste}}
983
983
  </div> -->
984
984
  <div style="padding: 100px">
985
- <div class="panel panel-default">
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 { initializeApp } from 'firebase/app'
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,16 @@ 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: 1 / 0.75,
37
+ minCropBoxWidth: 200,
38
+ minCropBoxHeight: 200,
39
+ minCanvasHeight: 100,
40
+ minContainerHeight: 100,
41
+ height: '124px',
42
+ }
43
+
33
44
  $scope.configDocument = {
34
45
  document: dataDocument,
35
46
  preview: true,