@@ -3,6 +3,8 @@ import {gettext} from 'core/utils';
33import { AuthoringWorkspaceService } from 'apps/authoring/authoring/services/AuthoringWorkspaceService' ;
44import { IDesk , ISuperdeskQuery , IUser } from 'superdesk-api' ;
55import { appConfig } from 'appConfig' ;
6+ import { sdApi } from 'api' ;
7+ import { getMonitoringViewOptions } from './utils' ;
68
79const PAGE_SIZE = 50 ;
810
@@ -23,7 +25,7 @@ interface IScope extends ng.IScope {
2325 group : any ;
2426 refreshGroup ( group ?: any , triggeredByScrolling ?: boolean ) ;
2527 isActiveGroup : ( group : any ) => boolean ;
26- switchView : ( value : any , swimlane ?: any ) => void ;
28+ switchView : ( value : any , options ?: { programmatic ?: boolean } ) => void ;
2729 gettext : ( text : any , params ?: any ) => any ;
2830 toggleFilter : ( ) => void ;
2931 addResourceUpdatedEventListener : ( callback : any ) => void ;
@@ -35,6 +37,7 @@ interface IScope extends ng.IScope {
3537 afterWorkspaceRename : ( ) => void ;
3638 initWorkspaceRename : ( workspace ) => void ;
3739 workspaceToRename : any ;
40+ availableViews : Array < { id : string ; label : string ; icon : string } > ;
3841}
3942
4043/**
@@ -130,7 +133,17 @@ export function MonitoringView(
130133 pageTitle . setUrl ( _ . capitalize ( gettext ( scope . type ) ) ) ;
131134
132135 scope . shouldRefresh = true ;
133- scope . view = 'compact' ; // default view
136+
137+ scope . availableViews = getMonitoringViewOptions ( {
138+ swimlaneViewEnabled :
139+ ! scope . monitoring . singleGroup
140+ && scope . type === 'monitoring'
141+ && scope . monitoring . hasSwimlaneView ,
142+ compactViewEnabled : scope . compactViewEnabled ,
143+ } ) ;
144+
145+ // will be initialized by programmatic call to `scope.switchView `
146+ scope . view = undefined ;
134147
135148 scope . workspaces = workspaces ;
136149 scope . $watch ( 'workspaces.active' , ( workspace ) => {
@@ -199,38 +212,32 @@ export function MonitoringView(
199212 } ) ;
200213 }
201214
202- if ( currentDesk && currentDesk . monitoring_default_view ) {
203- switch ( currentDesk . monitoring_default_view ) {
204- case 'list' :
205- scope . switchView ( 'compact' ) ;
206- break ;
207- case 'list-compact' :
208- scope . switchView ( 'compact-configurable' ) ;
209- break ;
210- case 'swimlane' :
211- scope . switchView ( 'compact' , true ) ;
212- break ;
213- case 'photogrid' :
214- scope . switchView ( 'photogrid' ) ;
215- break ;
216- default :
217- scope . switchView ( 'compact' ) ; // list by default
218- break ;
219- }
220- }
215+ const availableViewIds = new Set ( scope . availableViews . map ( ( { id} ) => id ) ) ;
216+ const deskPreference =
217+ scope . availableViews . find ( ( { id} ) => id === currentDesk ?. monitoring_default_view ) ?. id ;
218+ const userPreference : string = sdApi . preferences . get ( 'monitoring:view' ) ?. view ;
219+ const appliedPreference = deskPreference ?? userPreference ;
220+
221+ scope . switchView (
222+ availableViewIds . has ( appliedPreference ) ? appliedPreference : 'compact' ,
223+ { programmatic : true } ,
224+ ) ;
221225 } ) ;
222226
223227 scope . numberOfColumns = 1 ;
224228
225- /**
226- * Toggle viewColumn to switch views between swimlane and list
227- * @param {Boolean } value
228- * @param {Boolean } swimlane
229- */
230- scope . switchView = function ( value , swimlane ) {
231- scope . monitoring . switchViewColumn ( swimlane , true ) ;
229+ scope . switchView = function ( value : string , options ?: { programmatic ?: boolean } ) {
230+ const isSwimlane = value === 'swimlane2' ;
231+
232+ const programmatic = options ?. programmatic === true ;
233+
234+ scope . monitoring . switchViewColumn ( isSwimlane , ! programmatic ) ;
232235 scope . view = value ;
233- scope . swimlane = swimlane ;
236+ scope . swimlane = isSwimlane ;
237+
238+ if ( ! programmatic ) {
239+ sdApi . preferences . update ( 'monitoring:view' , { view : value } ) ;
240+ }
234241 } ;
235242
236243 /**
0 commit comments