All files / src/Repository RepositoryEventHub.ts

100% Statements 51/51
100% Branches 2/2
100% Functions 14/14
100% Lines 51/51
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269            1x             1x 1x             1x                       1x                               1x                             1x             1x                     1x                               1x                               1x                                       1x                             1x                                       1x 388x 388x 388x 388x 388x 388x 388x 388x 388x 388x 388x 388x         388x 8x 6x   5x 6x   1190x   2x 2x   15x 7x   2x 2x   10x           388x         388x         388x         388x         388x         388x         388x         388x         388x         388x         388x         388x      
/**
 * @module Repository
 */
/** */
 
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';
 
import { IContent, SavedContent } from '../Content';
import { ICustomActionOptions, IODataParams } from '../ODataApi';
import { UploadProgressInfo } from './UploadModels';
 
// tslint:disable-next-line:no-namespace
export namespace EventModels {
    export class Created {
        /**
         * The created Content instance
         */
        public Content: SavedContent;
    }
 
    export class CreateFailed {
        /**
         * The unsaved Content instance
         */
        public Content: IContent;
 
        /**
         * The Error that caused the failure
         */
        public Error: any;
    }
 
    export class Modified {
        /**
         * The Content instance that has been modified.
         */
        public Content: SavedContent;
 
        /**
         * The original fields
         */
        public OriginalFields: IContent;
        /**
         * The Change data
         */
        public Changes: IContent;
    }
 
    export class ModificationFailed {
        /**
         * The Content instance that has been failed to modify
         */
        public Content: SavedContent;
        /**
         * The Fields that you've been tried to modify
         */
        public Fields?: IContent;
        /**
         * The Error that caused the failure
         */
        public Error: any;
    }
 
    export class Loaded {
        /**
         * The Loaded content instance
         */
        public Content: SavedContent;
    }
 
    export class Deleted {
        /**
         * The Content data that has been deleted
         */
        public ContentData: IContent;
        /**
         * Indicates if the Content was deleted permanently or just moved to Trash
         */
        public Permanently: boolean;
    }
 
    export class DeleteFailed {
        /**
         * The Content that you've tried to delete
         */
        public Content: SavedContent;
        /**
         * Indicates if you've tried to delete the Content permanently or just tried to move it to the Trash
         */
        public Permanently: boolean;
 
        /**
         * The Error that caused the failure
         */
        public Error: any;
    }
 
    export class CustomActionExecuted<T extends IContent> {
        /**
         * The Action options
         */
        public ActionOptions: ICustomActionOptions;
        /**
         * The additional OData parameters (optional)
         */
        // tslint:disable-next-line:naming-convention
        public ODataParams?: IODataParams<T>;
        /**
         * The Action result
         */
        public Result: any;
    }
 
    export class CustomActionFailed<T extends IContent> {
        /**
         * The Action options
         */
        public ActionOptions: ICustomActionOptions;
        /**
         * The additional OData parameters (optional)
         */
        // tslint:disable-next-line:naming-convention
        public ODataParams?: IODataParams<T>;
        /**
         * The Type of the Result object
         */
        public ResultType: { new(...args: any[]): any };
        /**
         * The Error that caused the failure
         */
        public Error: any;
    }
 
    export class ContentMoved {
        /**
         * The From path (the original Parent's Path)
         */
        public From: string;
        /**
         * The destination path (the new Parent's Path)
         */
        public To: string;
        /**
         * The moved Content instance
         */
        public Content: SavedContent;
    }
 
    export class ContentMoveFailed {
        /**
         * The From path (the original Parent's Path)
         */
        public From: string;
        /**
         * The destination path (the new Parent's Path)
         */
        public To: string;
        /**
         * The Content instance that you've tried to move
         */
        public Content: SavedContent;
        /**
         * The Error that caused the failure
         */
        public Error: any;
    }
}
 
export class RepositoryEventHub {
    private readonly _onContentCreatedSubject = new Subject<EventModels.Created>();
    private readonly _onContentCreateFailedSubject = new Subject<EventModels.CreateFailed>();
    private readonly _onContentModifiedSubject = new Subject<EventModels.Modified>();
    private readonly _onContentModificationFailedSubject = new Subject<EventModels.ModificationFailed>();
    private readonly _onContentLoadedSubject = new Subject<EventModels.Loaded>();
    private readonly _onContentDeletedSubject = new Subject<EventModels.Deleted>();
    private readonly _onContentDeleteFailedSubject = new Subject<EventModels.DeleteFailed>();
    private readonly _onCustomActionExecutedSubject = new Subject<EventModels.CustomActionExecuted<IContent>>();
    private readonly _onCustomActionFailedSubject = new Subject<EventModels.CustomActionFailed<IContent>>();
    private readonly _onContentMovedSubject = new Subject<EventModels.ContentMoved>();
    private readonly _onContentMoveFailedSubject = new Subject<EventModels.ContentMoveFailed>();
    private readonly _onUploadProgressSubject = new Subject<UploadProgressInfo<IContent>>();
 
    /**
     * Method group for triggering Repository events
     */
    public Trigger = {
        ContentCreated: (ev: EventModels.Created) => this._onContentCreatedSubject.next(ev),
        ContentCreateFailed: (ev: EventModels.CreateFailed) => this._onContentCreateFailedSubject.next(ev),
 
        ContentModified: (ev: EventModels.Modified) => this._onContentModifiedSubject.next(ev),
        ContentModificationFailed: (ev: EventModels.ModificationFailed) => this._onContentModificationFailedSubject.next(ev),
 
        ContentLoaded: (ev: EventModels.Loaded) => this._onContentLoadedSubject.next(ev),
 
        ContentDeleted: (ev: EventModels.Deleted) => this._onContentDeletedSubject.next(ev),
        ContentDeleteFailed: (ev: EventModels.DeleteFailed) => this._onContentDeleteFailedSubject.next(ev),
 
        CustomActionExecuted: (ev: EventModels.CustomActionExecuted<any>) => this._onCustomActionExecutedSubject.next(ev),
        CustomActionFailed: (ev: EventModels.CustomActionFailed<any>) => this._onCustomActionFailedSubject.next(ev),
 
        ContentMoved: (ev: EventModels.ContentMoved) => this._onContentMovedSubject.next(ev),
        ContentMoveFailed: (ev: EventModels.ContentMoveFailed) => this._onContentMoveFailedSubject.next(ev),
 
        UploadProgress: (ev: UploadProgressInfo<any>) => this._onUploadProgressSubject.next(ev)
    };
 
    /**
     * Triggered after a succesful Content creation
     */
    public OnContentCreated: Observable<EventModels.Created> = this._onContentCreatedSubject.asObservable();
 
    /**
     * Triggered after Content creation has been failed
     */
    public OnContentCreateFailed = this._onContentCreateFailedSubject.asObservable();
 
    /**
     * Triggered after modifying a Content
     */
    public OnContentModified = this._onContentModifiedSubject.asObservable();
 
    /**
     * Triggered when failed to modify a Content
     */
    public OnContentModificationFailed = this._onContentModificationFailedSubject.asObservable();
 
    /**
     * Triggered when a Content is loaded from the Repository
     */
    public OnContentLoaded = this._onContentLoadedSubject.asObservable();
 
    /**
     * Triggered after deleting a Content
     */
    public OnContentDeleted = this._onContentDeletedSubject.asObservable();
 
    /**
     * Triggered after deleting a content has been failed
     */
    public OnContentDeleteFailed = this._onContentDeleteFailedSubject.asObservable();
 
    /**
     * Triggered after moving a content to another location
     */
    public OnContentMoved = this._onContentMovedSubject.asObservable();
 
    /**
     * Triggered after moving a content has been failed
     */
    public OnContentMoveFailed = this._onContentMoveFailedSubject.asObservable();
 
    /**
     * Triggered after a custom OData Action has been executed
     */
    public OnCustomActionExecuted = this._onCustomActionExecutedSubject.asObservable();
 
    /**
     * Triggered after a custom OData Action has been failed
     */
    public OnCustomActionFailed = this._onCustomActionFailedSubject.asObservable();
 
    /**
     * Triggered on Upload progress
     */
    public OnUploadProgress = this._onUploadProgressSubject.asObservable();
 
}