mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
fix upload demo and inject uploadservice
This commit is contained in:
@@ -22,7 +22,7 @@ import { AlfrescoTranslationLoader } from './AlfrescoTranslationLoader.service';
|
|||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AlfrescoTranslationService extends TranslateService {
|
export class AlfrescoTranslationService extends TranslateService {
|
||||||
userLang: string;
|
userLang: string = 'en' ;
|
||||||
currentLoader: AlfrescoTranslationLoader;
|
currentLoader: AlfrescoTranslationLoader;
|
||||||
|
|
||||||
constructor(http: Http, currentLoader: AlfrescoTranslationLoader, @Optional() missingTranslationHandler: MissingTranslationHandler) {
|
constructor(http: Http, currentLoader: AlfrescoTranslationLoader, @Optional() missingTranslationHandler: MissingTranslationHandler) {
|
||||||
|
@@ -96,8 +96,8 @@ Example of an App that declares upload button component :
|
|||||||
import { Component } from 'angular2/core';
|
import { Component } from 'angular2/core';
|
||||||
import { bootstrap } from 'angular2/platform/browser';
|
import { bootstrap } from 'angular2/platform/browser';
|
||||||
import { HTTP_PROVIDERS } from 'angular2/http';
|
import { HTTP_PROVIDERS } from 'angular2/http';
|
||||||
import { AlfrescoTranslationService, AlfrescoTranslationLoader } from 'ng2-alfresco-core/services';
|
import { AlfrescoSettingsService, AlfrescoTranslationService, AlfrescoTranslationLoader } from 'ng2-alfresco-core/services';
|
||||||
import { ALFRESCO_ULPOAD_COMPONENT } from 'ng2-alfresco-upload/ng2-alfresco-upload';
|
import { ALFRESCO_ULPOAD_COMPONENT, UploadService } from 'ng2-alfresco-upload/ng2-alfresco-upload';
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -111,15 +111,17 @@ import { ALFRESCO_ULPOAD_COMPONENT } from 'ng2-alfresco-upload/ng2-alfresco-uplo
|
|||||||
directives: [ALFRESCO_ULPOAD_COMPONENT]
|
directives: [ALFRESCO_ULPOAD_COMPONENT]
|
||||||
})
|
})
|
||||||
export class MyDemoApp {
|
export class MyDemoApp {
|
||||||
constructor() {
|
constructor(alfrescoSettingsService: AlfrescoSettingsService) {
|
||||||
|
alfrescoSettingsService.host = 'http://myalfrescoip';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bootstrap(MyDemoApp, [
|
bootstrap(MyDemoApp, [
|
||||||
HTTP_PROVIDERS,
|
HTTP_PROVIDERS,
|
||||||
AlfrescoTranslationService,
|
AlfrescoTranslationService,
|
||||||
AlfrescoTranslationLoader
|
AlfrescoTranslationLoader,
|
||||||
|
AlfrescoSettingsService,
|
||||||
|
UploadService
|
||||||
]);
|
]);
|
||||||
```
|
```
|
||||||
#### Options
|
#### Options
|
||||||
@@ -145,8 +147,8 @@ Example of an App that declares upload drag and drop component :
|
|||||||
import { Component } from 'angular2/core';
|
import { Component } from 'angular2/core';
|
||||||
import { bootstrap } from 'angular2/platform/browser';
|
import { bootstrap } from 'angular2/platform/browser';
|
||||||
import { HTTP_PROVIDERS } from 'angular2/http';
|
import { HTTP_PROVIDERS } from 'angular2/http';
|
||||||
import { AlfrescoTranslationService, AlfrescoTranslationLoader } from 'ng2-alfresco-core/services';
|
import { AlfrescoSettingsService, AlfrescoTranslationService, AlfrescoTranslationLoader } from 'ng2-alfresco-core/services';
|
||||||
import { ALFRESCO_ULPOAD_COMPONENT } from 'ng2-alfresco-upload/ng2-alfresco-upload';
|
import { ALFRESCO_ULPOAD_COMPONENT, UploadService } from 'ng2-alfresco-upload/ng2-alfresco-upload';
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -159,15 +161,17 @@ import { ALFRESCO_ULPOAD_COMPONENT } from 'ng2-alfresco-upload/ng2-alfresco-uplo
|
|||||||
directives: [ALFRESCO_ULPOAD_COMPONENT]
|
directives: [ALFRESCO_ULPOAD_COMPONENT]
|
||||||
})
|
})
|
||||||
export class MyDemoApp {
|
export class MyDemoApp {
|
||||||
constructor() {
|
constructor(alfrescoSettingsService: AlfrescoSettingsService) {
|
||||||
|
alfrescoSettingsService.host = 'http://myalfrescoip';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bootstrap(MyDemoApp, [
|
bootstrap(MyDemoApp, [
|
||||||
HTTP_PROVIDERS,
|
HTTP_PROVIDERS,
|
||||||
AlfrescoTranslationService,
|
AlfrescoTranslationService,
|
||||||
AlfrescoTranslationLoader
|
AlfrescoTranslationLoader,
|
||||||
|
AlfrescoSettingsService,
|
||||||
|
UploadService
|
||||||
]);
|
]);
|
||||||
```
|
```
|
||||||
#### Options
|
#### Options
|
||||||
|
@@ -27,8 +27,8 @@
|
|||||||
System.config({
|
System.config({
|
||||||
defaultJSExtensions: true,
|
defaultJSExtensions: true,
|
||||||
map: {
|
map: {
|
||||||
'ng2-alfresco-core': 'node_modules/ng2-alfresco-core',
|
'ng2-alfresco-core': 'node_modules/ng2-alfresco-core/dist',
|
||||||
'ng2-alfresco-upload': 'node_modules/ng2-alfresco-upload',
|
'ng2-alfresco-upload': 'node_modules/ng2-alfresco-upload/dist',
|
||||||
'ng2-translate': 'node_modules/ng2-translate',
|
'ng2-translate': 'node_modules/ng2-translate',
|
||||||
'rxjs': 'node_modules/rxjs',
|
'rxjs': 'node_modules/rxjs',
|
||||||
'angular2' : 'node_modules/angular2',
|
'angular2' : 'node_modules/angular2',
|
||||||
|
@@ -13,7 +13,7 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"alfresco-core-rest-api": "^0.1.0",
|
"alfresco-core-rest-api": "^0.1.0",
|
||||||
"angular2": "2.0.0-beta.13",
|
"angular2": "2.0.0-beta.15",
|
||||||
"es6-promise": "3.0.2",
|
"es6-promise": "3.0.2",
|
||||||
"es6-shim": "0.35.0",
|
"es6-shim": "0.35.0",
|
||||||
"material-design-icons": "^2.2.3",
|
"material-design-icons": "^2.2.3",
|
||||||
@@ -28,8 +28,8 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"http-server": "0.8.5",
|
"http-server": "0.8.5",
|
||||||
"systemjs": "0.19.17",
|
"systemjs": "0.19.17",
|
||||||
"typescript": "1.7.5",
|
"typescript": "^1.8.10",
|
||||||
"typings": "0.6.8"
|
"typings": "^0.7.12"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"angular2",
|
"angular2",
|
||||||
|
@@ -1,4 +1,6 @@
|
|||||||
/**
|
///<reference path="../node_modules/angular2/typings/browser.d.ts"/>
|
||||||
|
|
||||||
|
/*!
|
||||||
* @license
|
* @license
|
||||||
* Copyright 2016 Alfresco Software, Ltd.
|
* Copyright 2016 Alfresco Software, Ltd.
|
||||||
*
|
*
|
||||||
@@ -18,8 +20,8 @@
|
|||||||
import { Component } from 'angular2/core';
|
import { Component } from 'angular2/core';
|
||||||
import { bootstrap } from 'angular2/platform/browser';
|
import { bootstrap } from 'angular2/platform/browser';
|
||||||
import { HTTP_PROVIDERS } from 'angular2/http';
|
import { HTTP_PROVIDERS } from 'angular2/http';
|
||||||
import { AlfrescoTranslationService, AlfrescoTranslationLoader } from 'ng2-alfresco-core/services';
|
import { AlfrescoSettingsService, AlfrescoTranslationService, AlfrescoTranslationLoader } from 'ng2-alfresco-core/services';
|
||||||
import { ALFRESCO_ULPOAD_COMPONENT } from 'ng2-alfresco-upload/ng2-alfresco-upload';
|
import { ALFRESCO_ULPOAD_COMPONENT, UploadService } from 'ng2-alfresco-upload/ng2-alfresco-upload';
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -56,13 +58,15 @@ import { ALFRESCO_ULPOAD_COMPONENT } from 'ng2-alfresco-upload/ng2-alfresco-uplo
|
|||||||
directives: [ALFRESCO_ULPOAD_COMPONENT]
|
directives: [ALFRESCO_ULPOAD_COMPONENT]
|
||||||
})
|
})
|
||||||
export class MyDemoApp {
|
export class MyDemoApp {
|
||||||
constructor() {
|
constructor(alfrescoSettingsService: AlfrescoSettingsService) {
|
||||||
|
alfrescoSettingsService.host = 'http://192.168.99.100:2323';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bootstrap(MyDemoApp, [
|
bootstrap(MyDemoApp, [
|
||||||
HTTP_PROVIDERS,
|
HTTP_PROVIDERS,
|
||||||
AlfrescoTranslationService,
|
AlfrescoTranslationService,
|
||||||
AlfrescoTranslationLoader
|
AlfrescoTranslationLoader,
|
||||||
|
AlfrescoSettingsService,
|
||||||
|
UploadService
|
||||||
]);
|
]);
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "ng2-alfresco-upload",
|
"name": "ng2-alfresco-upload",
|
||||||
"description": "Alfresco Angular2 Upload Component",
|
"description": "Alfresco Angular2 Upload Component",
|
||||||
"version": "0.1.3",
|
"version": "0.1.4",
|
||||||
"author": "Alfresco Software, Ltd.",
|
"author": "Alfresco Software, Ltd.",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"typings": "typings install",
|
"typings": "typings install",
|
||||||
|
@@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
import { Component, ViewChild, ElementRef, Input, Output, EventEmitter, Optional } from 'angular2/core';
|
import { Component, ViewChild, ElementRef, Input, Output, EventEmitter } from 'angular2/core';
|
||||||
import { UploadService } from '../services/upload.service';
|
import { UploadService } from '../services/upload.service';
|
||||||
import { FileModel } from '../models/file.model';
|
import { FileModel } from '../models/file.model';
|
||||||
import { FileUploadingDialogComponent } from './file-uploading-dialog.component';
|
import { FileUploadingDialogComponent } from './file-uploading-dialog.component';
|
||||||
@@ -89,17 +89,16 @@ export class UploadButtonComponent {
|
|||||||
|
|
||||||
translate: AlfrescoTranslationService;
|
translate: AlfrescoTranslationService;
|
||||||
|
|
||||||
private _uploaderService: UploadService;
|
|
||||||
|
|
||||||
constructor(public el: ElementRef,
|
constructor(public el: ElementRef,
|
||||||
@Optional() translate: AlfrescoTranslationService) {
|
private _uploaderService: UploadService,
|
||||||
|
translate: AlfrescoTranslationService) {
|
||||||
console.log('UploadComponent constructor', el);
|
console.log('UploadComponent constructor', el);
|
||||||
|
|
||||||
let site = this.getSiteId();
|
let site = this.getSiteId();
|
||||||
let container = this.getContainerId();
|
let container = this.getContainerId();
|
||||||
|
|
||||||
this._uploaderService = new UploadService({
|
this._uploaderService.setOptions({
|
||||||
fieldName: 'filedata',
|
|
||||||
formFields: {
|
formFields: {
|
||||||
siteid: site,
|
siteid: site,
|
||||||
containerid: container
|
containerid: container
|
||||||
|
@@ -42,8 +42,6 @@ declare let __moduleName: string;
|
|||||||
})
|
})
|
||||||
export class UploadDragAreaComponent {
|
export class UploadDragAreaComponent {
|
||||||
|
|
||||||
private _uploaderService: UploadService;
|
|
||||||
|
|
||||||
@ViewChild('fileUploadingDialog')
|
@ViewChild('fileUploadingDialog')
|
||||||
fileUploadingDialogComponent: FileUploadingDialogComponent;
|
fileUploadingDialogComponent: FileUploadingDialogComponent;
|
||||||
|
|
||||||
@@ -61,13 +59,14 @@ export class UploadDragAreaComponent {
|
|||||||
@Output()
|
@Output()
|
||||||
onSuccess = new EventEmitter();
|
onSuccess = new EventEmitter();
|
||||||
|
|
||||||
constructor(public el: ElementRef) {
|
constructor(public el: ElementRef,
|
||||||
|
private _uploaderService: UploadService) {
|
||||||
console.log('UploadComponent constructor', el);
|
console.log('UploadComponent constructor', el);
|
||||||
|
|
||||||
let site = this.getSiteId();
|
let site = this.getSiteId();
|
||||||
let container = this.getContainerId();
|
let container = this.getContainerId();
|
||||||
|
|
||||||
this._uploaderService = new UploadService({
|
this._uploaderService.setOptions({
|
||||||
fieldName: 'filedata',
|
fieldName: 'filedata',
|
||||||
formFields: {
|
formFields: {
|
||||||
siteid: site,
|
siteid: site,
|
||||||
|
@@ -17,9 +17,10 @@
|
|||||||
|
|
||||||
|
|
||||||
import { FileModel } from '../models/file.model';
|
import { FileModel } from '../models/file.model';
|
||||||
import { EventEmitter } from 'angular2/core';
|
import { EventEmitter, Injectable } from 'angular2/core';
|
||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
import { Response } from 'angular2/http';
|
import { Response } from 'angular2/http';
|
||||||
|
import { AlfrescoSettingsService } from 'ng2-alfresco-core/services';
|
||||||
|
|
||||||
declare let AlfrescoApi: any;
|
declare let AlfrescoApi: any;
|
||||||
|
|
||||||
@@ -29,27 +30,37 @@ declare let AlfrescoApi: any;
|
|||||||
*
|
*
|
||||||
* @returns {UploadService} .
|
* @returns {UploadService} .
|
||||||
*/
|
*/
|
||||||
|
@Injectable()
|
||||||
export class UploadService {
|
export class UploadService {
|
||||||
private _host: string = 'http://192.168.99.100:8080';
|
private _host: string = 'http://192.168.99.100:8080';
|
||||||
private _baseUrlPath: string = '/alfresco/api/-default-/public/alfresco/versions/1';
|
private _baseUrlPath: string = '/alfresco/api/-default-/public/alfresco/versions/1';
|
||||||
private _url: string = '/alfresco/service/api/upload';
|
private _url: string = '/alfresco/service/api/upload';
|
||||||
|
|
||||||
private _method: string = 'POST';
|
private _method: string = 'POST';
|
||||||
private _fieldName: string = 'file';
|
private _fieldName: string = 'filedata';
|
||||||
private _formFields: Object = {};
|
private _formFields: Object = {};
|
||||||
|
|
||||||
private _queue: FileModel[] = [];
|
private _queue: FileModel[] = [];
|
||||||
|
|
||||||
private _alfrescoClient: any;
|
private _alfrescoClient: any;
|
||||||
|
|
||||||
constructor(private options: any) {
|
constructor(private settings: AlfrescoSettingsService) {
|
||||||
console.log('UploadService constructor');
|
console.log('UploadService constructor');
|
||||||
|
|
||||||
|
if (settings) {
|
||||||
|
this._host = settings.host;
|
||||||
|
}
|
||||||
this._alfrescoClient = this.getAlfrescoClient();
|
this._alfrescoClient = this.getAlfrescoClient();
|
||||||
|
}
|
||||||
|
|
||||||
this._host = options.host || this._host;
|
/**
|
||||||
|
* Configure the service
|
||||||
|
*
|
||||||
|
* @param {Object} - options to init the object
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public setOptions(options: any): void {
|
||||||
this._baseUrlPath = options.baseUrlPath || this._baseUrlPath;
|
this._baseUrlPath = options.baseUrlPath || this._baseUrlPath;
|
||||||
this._fieldName = options.fieldName != null ? options.fieldName : this._fieldName;
|
|
||||||
this._formFields = options.formFields != null ? options.formFields : this._formFields;
|
this._formFields = options.formFields != null ? options.formFields : this._formFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user