@@ -24,52 +24,28 @@ export class AccessPermissionSandbox extends Sandbox {
2424 public permissions$ : Observable < Permission [ ] > = this . store . select ( fromStore . getLoadPermissionsData ) ;
2525
2626 /**
27- * Create permission loading
27+ * Save permission pending
2828 *
2929 * @type {Observable<boolean> }
3030 * @memberof AccessPermissionSandbox
3131 */
32- public createPermissionLoading $ : Observable < boolean > = this . store . select ( fromStore . getCreatePermissionLoading ) ;
32+ public savePermissionPending $ : Observable < boolean > = this . store . select ( fromStore . getSavePermissionPending ) ;
3333
3434 /**
35- * Create permission loaded
35+ * Save permission completed
3636 *
3737 * @type {Observable<boolean> }
3838 * @memberof AccessPermissionSandbox
3939 */
40- public createPermissionLoaded $ : Observable < boolean > = this . store . select ( fromStore . getCreatePermissionLoaded ) ;
40+ public savePermissionCompleted $ : Observable < boolean > = this . store . select ( fromStore . getSavePermissionCompleted ) ;
4141
4242 /**
43- * Create permission error
43+ * Save permission error
4444 *
4545 * @type {Observable<any> }
4646 * @memberof AccessPermissionSandbox
4747 */
48- public createPermissionError$ : Observable < any > = this . store . select ( fromStore . getCreatePermissionError ) ;
49-
50- /**
51- * Update permission loading
52- *
53- * @type {Observable<boolean> }
54- * @memberof AccessPermissionSandbox
55- */
56- public updatePermissionLoading$ : Observable < boolean > = this . store . select ( fromStore . getUpdatePermissionLoading ) ;
57-
58- /**
59- * Update permission loaded
60- *
61- * @type {Observable<boolean> }
62- * @memberof AccessPermissionSandbox
63- */
64- public updatePermissionLoaded$ : Observable < boolean > = this . store . select ( fromStore . getUpdatePermissionLoaded ) ;
65-
66- /**
67- * Update permission error
68- *
69- * @type {Observable<any> }
70- * @memberof AccessPermissionSandbox
71- */
72- public updatePermissionError$ : Observable < any > = this . store . select ( fromStore . getUpdatePermissionError ) ;
48+ public savePermissionError$ : Observable < any > = this . store . select ( fromStore . getSavePermissionError ) ;
7349
7450 /**
7551 * Viewing permission
@@ -120,37 +96,34 @@ export class AccessPermissionSandbox extends Sandbox {
12096 private utilService : UtilService
12197 ) {
12298 super ( ) ;
123- this . registerAuthEvents ( ) ;
124- console . log ( "calling permission sandbox constructor" ) ;
12599 }
126100
127101 /**
128- * Un-Register events
102+ * Un-Register subscribers
129103 *
130104 * @memberof AccessPermissionSandbox
131105 */
132- public unregisterEvents ( ) {
106+ public unregisterSubscribers ( ) {
133107 this . subscriptions . forEach ( sub => sub . unsubscribe ( ) ) ;
134108 }
135109
136110 /**
137- * Register auth events
111+ * Register subscribers
138112 *
139113 * @private
140114 * @memberof AccessPermissionSandbox
141115 */
142- private registerAuthEvents ( ) : void {
143- const createSub = this . createPermissionLoaded $. subscribe ( loaded => {
144- if ( loaded ) {
145- this . utilService . displayNotification ( 'accessPermission.createdSuccessfully ' , 'success' ) ;
116+ public registerSubscribers ( ) : void {
117+ const saveCompleted = this . savePermissionCompleted $. subscribe ( completed => {
118+ if ( completed ) {
119+ this . utilService . displayNotification ( 'accessPermission.savedSuccessfully ' , 'success' ) ;
146120 this . utilService . navigateAfter ( [ '/admin/access/permission/list' ] ) ;
147121 }
148122 } ) ;
149123
150- const updateSub = this . updatePermissionLoaded$ . subscribe ( loaded => {
151- if ( loaded ) {
152- this . utilService . displayNotification ( 'accessPermission.updatedSuccessfully' , 'success' ) ;
153- this . utilService . navigateAfter ( [ '/admin/access/permission/list' ] ) ;
124+ const saveError = this . savePermissionError$ . subscribe ( err => {
125+ if ( err ) {
126+ this . utilService . displayNotification ( err . json ( ) . error . message , 'error' ) ;
154127 }
155128 } ) ;
156129
@@ -160,19 +133,7 @@ export class AccessPermissionSandbox extends Sandbox {
160133 }
161134 } ) ;
162135
163- const createErrSub = this . createPermissionError$ . subscribe ( data => {
164- if ( data ) {
165- this . utilService . displayNotification ( data . json ( ) . error . message , 'error' ) ;
166- }
167- } ) ;
168-
169- const updateErrSub = this . updatePermissionError$ . subscribe ( data => {
170- if ( data ) {
171- this . utilService . displayNotification ( data . json ( ) . error . message , 'error' ) ;
172- }
173- } ) ;
174-
175- this . subscriptions = [ createSub , updateSub , deleteSub , createErrSub , updateErrSub ] ;
136+ this . subscriptions = [ deleteSub , saveCompleted , saveError ] ;
176137 }
177138
178139 /**
@@ -191,7 +152,7 @@ export class AccessPermissionSandbox extends Sandbox {
191152 * @memberof AccessPermissionSandbox
192153 */
193154 public createPermission ( form : PermissionForm ) {
194- this . store . dispatch ( new fromStore . CreatePermissionAction ( form ) ) ;
155+ this . store . dispatch ( new fromStore . SavePermissionAction ( form ) ) ;
195156 }
196157
197158 /**
@@ -201,7 +162,7 @@ export class AccessPermissionSandbox extends Sandbox {
201162 * @memberof AccessPermissionSandbox
202163 */
203164 public updatePermission ( form : PermissionForm ) {
204- this . store . dispatch ( new fromStore . UpdatePermissionAction ( form ) ) ;
165+ this . store . dispatch ( new fromStore . SavePermissionAction ( form ) ) ;
205166 }
206167
207168 /**
@@ -233,4 +194,52 @@ export class AccessPermissionSandbox extends Sandbox {
233194 public deleteMultiplePermissions ( ids : Array < number > ) {
234195 this . store . dispatch ( new fromStore . DeleteMultiplePermissionAction ( { ids} ) ) ;
235196 }
197+
198+ /**
199+ * Reset all states
200+ *
201+ * @memberof AccessPermissionSandbox
202+ */
203+ public resetAllStates ( ) {
204+ this . store . dispatch ( new fromStore . ResetLoadPermissionAction ( ) ) ;
205+ this . store . dispatch ( new fromStore . ResetDeletePermissionAction ( ) ) ;
206+ this . store . dispatch ( new fromStore . ResetViewPermissionAction ( ) ) ;
207+ this . store . dispatch ( new fromStore . ResetSavePermissionAction ( ) ) ;
208+ }
209+
210+ /**
211+ * Reset load state
212+ *
213+ * @memberof AccessPermissionSandbox
214+ */
215+ public resetLoadState ( ) {
216+ this . store . dispatch ( new fromStore . ResetLoadPermissionAction ( ) ) ;
217+ }
218+
219+ /**
220+ * Reset delete state
221+ *
222+ * @memberof AccessPermissionSandbox
223+ */
224+ public resetDeleteState ( ) {
225+ this . store . dispatch ( new fromStore . ResetDeletePermissionAction ( ) ) ;
226+ }
227+
228+ /**
229+ * Reset view state
230+ *
231+ * @memberof AccessPermissionSandbox
232+ */
233+ public resetViewState ( ) {
234+ this . store . dispatch ( new fromStore . ResetViewPermissionAction ( ) ) ;
235+ }
236+
237+ /**
238+ * Reset save state
239+ *
240+ * @memberof AccessPermissionSandbox
241+ */
242+ public resetSaveState ( ) {
243+ this . store . dispatch ( new fromStore . ResetSavePermissionAction ( ) ) ;
244+ }
236245}
0 commit comments