Passed
Push — master ( da5844...d3a53d )
by Morris
12:45 queued 10s
created
apps/dashboard/lib/Service/BackgroundService.php 1 patch
Indentation   +130 added lines, -130 removed lines patch added patch discarded remove patch
@@ -33,141 +33,141 @@
 block discarded – undo
33 33
 use OCP\IConfig;
34 34
 
35 35
 class BackgroundService {
36
-	public const THEMING_MODE_DARK = 'dark';
36
+    public const THEMING_MODE_DARK = 'dark';
37 37
 
38
-	public const SHIPPED_BACKGROUNDS = [
39
-		'anatoly-mikhaltsov-butterfly-wing-scale.jpg' => [
40
-			'attribution' => 'Butterfly wing scale (Anatoly Mikhaltsov, CC BY-SA)',
41
-			'attribution_url' => 'https://commons.wikimedia.org/wiki/File:%D0%A7%D0%B5%D1%88%D1%83%D0%B9%D0%BA%D0%B8_%D0%BA%D1%80%D1%8B%D0%BB%D0%B0_%D0%B1%D0%B0%D0%B1%D0%BE%D1%87%D0%BA%D0%B8.jpg',
42
-		],
43
-		'bernie-cetonia-aurata-take-off-composition.jpg' => [
44
-			'attribution' => 'Cetonia aurata take off composition (Bernie, Public Domain)',
45
-			'attribution_url' => 'https://commons.wikimedia.org/wiki/File:Cetonia_aurata_take_off_composition_05172009.jpg',
46
-			'theming' => self::THEMING_MODE_DARK,
47
-		],
48
-		'dejan-krsmanovic-ribbed-red-metal.jpg' => [
49
-			'attribution' => 'Ribbed red metal (Dejan Krsmanovic, CC BY)',
50
-			'attribution_url' => 'https://www.flickr.com/photos/dejankrsmanovic/42971456774/',
51
-		],
52
-		'eduardo-neves-pedra-azul.jpg' => [
53
-			'attribution' => 'Pedra azul milky way (Eduardo Neves, CC BY-SA)',
54
-			'attribution_url' => 'https://commons.wikimedia.org/wiki/File:Pedra_Azul_Milky_Way.jpg',
55
-		],
56
-		'european-space-agency-barents-bloom.jpg' => [
57
-			'attribution' => 'Barents bloom (European Space Agency, CC BY-SA)',
58
-			'attribution_url' => 'https://www.esa.int/ESA_Multimedia/Images/2016/08/Barents_bloom',
59
-		],
60
-		'hannes-fritz-flippity-floppity.jpg' => [
61
-			'attribution' => 'Flippity floppity (Hannes Fritz, CC BY-SA)',
62
-			'attribution_url' => 'http://hannes.photos/flippity-floppity',
63
-		],
64
-		'hannes-fritz-roulette.jpg' => [
65
-			'attribution' => 'Roulette (Hannes Fritz, CC BY-SA)',
66
-			'attribution_url' => 'http://hannes.photos/roulette',
67
-		],
68
-		'hannes-fritz-sea-spray.jpg' => [
69
-			'attribution' => 'Sea spray (Hannes Fritz, CC BY-SA)',
70
-			'attribution_url' => 'http://hannes.photos/sea-spray',
71
-		],
72
-		'kamil-porembinski-clouds.jpg' => [
73
-			'attribution' => 'Clouds (Kamil Porembiński, CC BY-SA)',
74
-			'attribution_url' => 'https://www.flickr.com/photos/paszczak000/8715851521/',
75
-		],
76
-		'bernard-spragg-new-zealand-fern.jpg' => [
77
-			'attribution' => 'New zealand fern (Bernard Spragg, CC0)',
78
-			'attribution_url' => 'https://commons.wikimedia.org/wiki/File:NZ_Fern.(Blechnum_chambersii)_(11263534936).jpg',
79
-		],
80
-		'rawpixel-pink-tapioca-bubbles.jpg' => [
81
-			'attribution' => 'Pink tapioca bubbles (Rawpixel, CC BY)',
82
-			'attribution_url' => 'https://www.flickr.com/photos/byrawpixel/27665140298/in/photostream/',
83
-			'theming' => self::THEMING_MODE_DARK,
84
-		],
85
-		'nasa-waxing-crescent-moon.jpg' => [
86
-			'attribution' => 'Waxing crescent moon (NASA, Public Domain)',
87
-			'attribution_url' => 'https://www.nasa.gov/image-feature/a-waxing-crescent-moon',
88
-		],
89
-		'tommy-chau-already.jpg' => [
90
-			'attribution' => 'Cityscape (Tommy Chau, CC BY)',
91
-			'attribution_url' => 'https://www.flickr.com/photos/90975693@N05/16910999368',
92
-		],
93
-		'tommy-chau-lion-rock-hill.jpg' => [
94
-			'attribution' => 'Lion rock hill (Tommy Chau, CC BY)',
95
-			'attribution_url' => 'https://www.flickr.com/photos/90975693@N05/17136440246',
96
-			'theming' => self::THEMING_MODE_DARK,
97
-		],
98
-		'lali-masriera-yellow-bricks.jpg' => [
99
-			'attribution' => 'Yellow bricks (Lali Masriera, CC BY)',
100
-			'attribution_url' => 'https://www.flickr.com/photos/visualpanic/3982464447',
101
-			'theming' => self::THEMING_MODE_DARK,
102
-		]
103
-	];
104
-	/**
105
-	 * @var \OCP\Files\Folder
106
-	 */
107
-	private $userFolder;
108
-	/**
109
-	 * @var \OCP\Files\SimpleFS\ISimpleFolder
110
-	 */
111
-	private $dashboardUserFolder;
112
-	/**
113
-	 * @var IConfig
114
-	 */
115
-	private $config;
116
-	private $userId;
38
+    public const SHIPPED_BACKGROUNDS = [
39
+        'anatoly-mikhaltsov-butterfly-wing-scale.jpg' => [
40
+            'attribution' => 'Butterfly wing scale (Anatoly Mikhaltsov, CC BY-SA)',
41
+            'attribution_url' => 'https://commons.wikimedia.org/wiki/File:%D0%A7%D0%B5%D1%88%D1%83%D0%B9%D0%BA%D0%B8_%D0%BA%D1%80%D1%8B%D0%BB%D0%B0_%D0%B1%D0%B0%D0%B1%D0%BE%D1%87%D0%BA%D0%B8.jpg',
42
+        ],
43
+        'bernie-cetonia-aurata-take-off-composition.jpg' => [
44
+            'attribution' => 'Cetonia aurata take off composition (Bernie, Public Domain)',
45
+            'attribution_url' => 'https://commons.wikimedia.org/wiki/File:Cetonia_aurata_take_off_composition_05172009.jpg',
46
+            'theming' => self::THEMING_MODE_DARK,
47
+        ],
48
+        'dejan-krsmanovic-ribbed-red-metal.jpg' => [
49
+            'attribution' => 'Ribbed red metal (Dejan Krsmanovic, CC BY)',
50
+            'attribution_url' => 'https://www.flickr.com/photos/dejankrsmanovic/42971456774/',
51
+        ],
52
+        'eduardo-neves-pedra-azul.jpg' => [
53
+            'attribution' => 'Pedra azul milky way (Eduardo Neves, CC BY-SA)',
54
+            'attribution_url' => 'https://commons.wikimedia.org/wiki/File:Pedra_Azul_Milky_Way.jpg',
55
+        ],
56
+        'european-space-agency-barents-bloom.jpg' => [
57
+            'attribution' => 'Barents bloom (European Space Agency, CC BY-SA)',
58
+            'attribution_url' => 'https://www.esa.int/ESA_Multimedia/Images/2016/08/Barents_bloom',
59
+        ],
60
+        'hannes-fritz-flippity-floppity.jpg' => [
61
+            'attribution' => 'Flippity floppity (Hannes Fritz, CC BY-SA)',
62
+            'attribution_url' => 'http://hannes.photos/flippity-floppity',
63
+        ],
64
+        'hannes-fritz-roulette.jpg' => [
65
+            'attribution' => 'Roulette (Hannes Fritz, CC BY-SA)',
66
+            'attribution_url' => 'http://hannes.photos/roulette',
67
+        ],
68
+        'hannes-fritz-sea-spray.jpg' => [
69
+            'attribution' => 'Sea spray (Hannes Fritz, CC BY-SA)',
70
+            'attribution_url' => 'http://hannes.photos/sea-spray',
71
+        ],
72
+        'kamil-porembinski-clouds.jpg' => [
73
+            'attribution' => 'Clouds (Kamil Porembiński, CC BY-SA)',
74
+            'attribution_url' => 'https://www.flickr.com/photos/paszczak000/8715851521/',
75
+        ],
76
+        'bernard-spragg-new-zealand-fern.jpg' => [
77
+            'attribution' => 'New zealand fern (Bernard Spragg, CC0)',
78
+            'attribution_url' => 'https://commons.wikimedia.org/wiki/File:NZ_Fern.(Blechnum_chambersii)_(11263534936).jpg',
79
+        ],
80
+        'rawpixel-pink-tapioca-bubbles.jpg' => [
81
+            'attribution' => 'Pink tapioca bubbles (Rawpixel, CC BY)',
82
+            'attribution_url' => 'https://www.flickr.com/photos/byrawpixel/27665140298/in/photostream/',
83
+            'theming' => self::THEMING_MODE_DARK,
84
+        ],
85
+        'nasa-waxing-crescent-moon.jpg' => [
86
+            'attribution' => 'Waxing crescent moon (NASA, Public Domain)',
87
+            'attribution_url' => 'https://www.nasa.gov/image-feature/a-waxing-crescent-moon',
88
+        ],
89
+        'tommy-chau-already.jpg' => [
90
+            'attribution' => 'Cityscape (Tommy Chau, CC BY)',
91
+            'attribution_url' => 'https://www.flickr.com/photos/90975693@N05/16910999368',
92
+        ],
93
+        'tommy-chau-lion-rock-hill.jpg' => [
94
+            'attribution' => 'Lion rock hill (Tommy Chau, CC BY)',
95
+            'attribution_url' => 'https://www.flickr.com/photos/90975693@N05/17136440246',
96
+            'theming' => self::THEMING_MODE_DARK,
97
+        ],
98
+        'lali-masriera-yellow-bricks.jpg' => [
99
+            'attribution' => 'Yellow bricks (Lali Masriera, CC BY)',
100
+            'attribution_url' => 'https://www.flickr.com/photos/visualpanic/3982464447',
101
+            'theming' => self::THEMING_MODE_DARK,
102
+        ]
103
+    ];
104
+    /**
105
+     * @var \OCP\Files\Folder
106
+     */
107
+    private $userFolder;
108
+    /**
109
+     * @var \OCP\Files\SimpleFS\ISimpleFolder
110
+     */
111
+    private $dashboardUserFolder;
112
+    /**
113
+     * @var IConfig
114
+     */
115
+    private $config;
116
+    private $userId;
117 117
 
118
-	public function __construct(IRootFolder $rootFolder, IAppData $appData, IConfig $config, $userId) {
119
-		if ($userId === null) {
120
-			return;
121
-		}
122
-		$this->userFolder = $rootFolder->getUserFolder($userId);
123
-		try {
124
-			$this->dashboardUserFolder = $appData->getFolder($userId);
125
-		} catch (NotFoundException $e) {
126
-			$this->dashboardUserFolder = $appData->newFolder($userId);
127
-		}
128
-		$this->config = $config;
129
-		$this->userId = $userId;
130
-	}
118
+    public function __construct(IRootFolder $rootFolder, IAppData $appData, IConfig $config, $userId) {
119
+        if ($userId === null) {
120
+            return;
121
+        }
122
+        $this->userFolder = $rootFolder->getUserFolder($userId);
123
+        try {
124
+            $this->dashboardUserFolder = $appData->getFolder($userId);
125
+        } catch (NotFoundException $e) {
126
+            $this->dashboardUserFolder = $appData->newFolder($userId);
127
+        }
128
+        $this->config = $config;
129
+        $this->userId = $userId;
130
+    }
131 131
 
132
-	public function setDefaultBackground(): void {
133
-		$this->config->deleteUserValue($this->userId, 'dashboard', 'background');
134
-	}
132
+    public function setDefaultBackground(): void {
133
+        $this->config->deleteUserValue($this->userId, 'dashboard', 'background');
134
+    }
135 135
 
136
-	/**
137
-	 * @param $path
138
-	 * @throws NotFoundException
139
-	 * @throws \OCP\Files\NotPermittedException
140
-	 * @throws \OCP\PreConditionNotMetException
141
-	 */
142
-	public function setFileBackground($path): void {
143
-		$this->config->setUserValue($this->userId, 'dashboard', 'background', 'custom');
144
-		/** @var \OCP\Files\File $file */
145
-		$file = $this->userFolder->get($path);
146
-		$this->dashboardUserFolder->newFile('background.jpg', $file->fopen('r'));
147
-	}
136
+    /**
137
+     * @param $path
138
+     * @throws NotFoundException
139
+     * @throws \OCP\Files\NotPermittedException
140
+     * @throws \OCP\PreConditionNotMetException
141
+     */
142
+    public function setFileBackground($path): void {
143
+        $this->config->setUserValue($this->userId, 'dashboard', 'background', 'custom');
144
+        /** @var \OCP\Files\File $file */
145
+        $file = $this->userFolder->get($path);
146
+        $this->dashboardUserFolder->newFile('background.jpg', $file->fopen('r'));
147
+    }
148 148
 
149
-	public function setShippedBackground($fileName): void {
150
-		if (!array_key_exists($fileName, self::SHIPPED_BACKGROUNDS)) {
151
-			throw new \InvalidArgumentException('The given file name is invalid');
152
-		}
153
-		$this->config->setUserValue($this->userId, 'dashboard', 'background', $fileName);
154
-	}
149
+    public function setShippedBackground($fileName): void {
150
+        if (!array_key_exists($fileName, self::SHIPPED_BACKGROUNDS)) {
151
+            throw new \InvalidArgumentException('The given file name is invalid');
152
+        }
153
+        $this->config->setUserValue($this->userId, 'dashboard', 'background', $fileName);
154
+    }
155 155
 
156
-	public function setColorBackground(string $color): void {
157
-		if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $color)) {
158
-			throw new \InvalidArgumentException('The given color is invalid');
159
-		}
160
-		$this->config->setUserValue($this->userId, 'dashboard', 'background', $color);
161
-	}
156
+    public function setColorBackground(string $color): void {
157
+        if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $color)) {
158
+            throw new \InvalidArgumentException('The given color is invalid');
159
+        }
160
+        $this->config->setUserValue($this->userId, 'dashboard', 'background', $color);
161
+    }
162 162
 
163
-	public function getBackground(): ?ISimpleFile {
164
-		$background = $this->config->getUserValue($this->userId, 'dashboard', 'background', 'default');
165
-		if ($background === 'custom') {
166
-			try {
167
-				return $this->dashboardUserFolder->getFile('background.jpg');
168
-			} catch (NotFoundException $e) {
169
-			}
170
-		}
171
-		return null;
172
-	}
163
+    public function getBackground(): ?ISimpleFile {
164
+        $background = $this->config->getUserValue($this->userId, 'dashboard', 'background', 'default');
165
+        if ($background === 'custom') {
166
+            try {
167
+                return $this->dashboardUserFolder->getFile('background.jpg');
168
+            } catch (NotFoundException $e) {
169
+            }
170
+        }
171
+        return null;
172
+    }
173 173
 }
Please login to merge, or discard this patch.
apps/dashboard/lib/Controller/DashboardController.php 1 patch
Indentation   +119 added lines, -119 removed lines patch added patch discarded remove patch
@@ -45,132 +45,132 @@
 block discarded – undo
45 45
 
46 46
 class DashboardController extends Controller {
47 47
 
48
-	/** @var IInitialStateService */
49
-	private $inititalStateService;
50
-	/** @var IEventDispatcher */
51
-	private $eventDispatcher;
52
-	/** @var IManager */
53
-	private $dashboardManager;
54
-	/** @var IConfig */
55
-	private $config;
56
-	/** @var string */
57
-	private $userId;
58
-	/**
59
-	 * @var BackgroundService
60
-	 */
61
-	private $backgroundService;
48
+    /** @var IInitialStateService */
49
+    private $inititalStateService;
50
+    /** @var IEventDispatcher */
51
+    private $eventDispatcher;
52
+    /** @var IManager */
53
+    private $dashboardManager;
54
+    /** @var IConfig */
55
+    private $config;
56
+    /** @var string */
57
+    private $userId;
58
+    /**
59
+     * @var BackgroundService
60
+     */
61
+    private $backgroundService;
62 62
 
63
-	public function __construct(
64
-		string $appName,
65
-		IRequest $request,
66
-		IInitialStateService $initialStateService,
67
-		IEventDispatcher $eventDispatcher,
68
-		IManager $dashboardManager,
69
-		IConfig $config,
70
-		BackgroundService $backgroundService,
71
-		$userId
72
-	) {
73
-		parent::__construct($appName, $request);
63
+    public function __construct(
64
+        string $appName,
65
+        IRequest $request,
66
+        IInitialStateService $initialStateService,
67
+        IEventDispatcher $eventDispatcher,
68
+        IManager $dashboardManager,
69
+        IConfig $config,
70
+        BackgroundService $backgroundService,
71
+        $userId
72
+    ) {
73
+        parent::__construct($appName, $request);
74 74
 
75
-		$this->inititalStateService = $initialStateService;
76
-		$this->eventDispatcher = $eventDispatcher;
77
-		$this->dashboardManager = $dashboardManager;
78
-		$this->config = $config;
79
-		$this->backgroundService = $backgroundService;
80
-		$this->userId = $userId;
81
-	}
75
+        $this->inititalStateService = $initialStateService;
76
+        $this->eventDispatcher = $eventDispatcher;
77
+        $this->dashboardManager = $dashboardManager;
78
+        $this->config = $config;
79
+        $this->backgroundService = $backgroundService;
80
+        $this->userId = $userId;
81
+    }
82 82
 
83
-	/**
84
-	 * @NoCSRFRequired
85
-	 * @NoAdminRequired
86
-	 * @return TemplateResponse
87
-	 */
88
-	public function index(): TemplateResponse {
89
-		\OCP\Util::addStyle('dashboard', 'dashboard');
90
-		$this->eventDispatcher->dispatchTyped(new LoadSidebar());
91
-		if (class_exists(LoadViewer::class)) {
92
-			$this->eventDispatcher->dispatchTyped(new LoadViewer());
93
-		}
83
+    /**
84
+     * @NoCSRFRequired
85
+     * @NoAdminRequired
86
+     * @return TemplateResponse
87
+     */
88
+    public function index(): TemplateResponse {
89
+        \OCP\Util::addStyle('dashboard', 'dashboard');
90
+        $this->eventDispatcher->dispatchTyped(new LoadSidebar());
91
+        if (class_exists(LoadViewer::class)) {
92
+            $this->eventDispatcher->dispatchTyped(new LoadViewer());
93
+        }
94 94
 
95
-		$this->eventDispatcher->dispatchTyped(new RegisterWidgetEvent($this->dashboardManager));
95
+        $this->eventDispatcher->dispatchTyped(new RegisterWidgetEvent($this->dashboardManager));
96 96
 
97
-		$userLayout = explode(',', $this->config->getUserValue($this->userId, 'dashboard', 'layout', 'recommendations,spreed,mail,calendar'));
98
-		$widgets = array_map(function (IWidget $widget) {
99
-			return [
100
-				'id' => $widget->getId(),
101
-				'title' => $widget->getTitle(),
102
-				'iconClass' => $widget->getIconClass(),
103
-				'url' => $widget->getUrl()
104
-			];
105
-		}, $this->dashboardManager->getWidgets());
106
-		$this->inititalStateService->provideInitialState('dashboard', 'panels', $widgets);
107
-		$this->inititalStateService->provideInitialState('dashboard', 'layout', $userLayout);
108
-		$this->inititalStateService->provideInitialState('dashboard', 'firstRun', $this->config->getUserValue($this->userId, 'dashboard', 'firstRun', '1') === '1');
109
-		$this->inititalStateService->provideInitialState('dashboard', 'shippedBackgrounds', BackgroundService::SHIPPED_BACKGROUNDS);
110
-		$this->inititalStateService->provideInitialState('dashboard', 'background', $this->config->getUserValue($this->userId, 'dashboard', 'background', 'default'));
111
-		$this->inititalStateService->provideInitialState('dashboard', 'version', $this->config->getUserValue($this->userId, 'dashboard', 'backgroundVersion', 0));
112
-		$this->config->setUserValue($this->userId, 'dashboard', 'firstRun', '0');
97
+        $userLayout = explode(',', $this->config->getUserValue($this->userId, 'dashboard', 'layout', 'recommendations,spreed,mail,calendar'));
98
+        $widgets = array_map(function (IWidget $widget) {
99
+            return [
100
+                'id' => $widget->getId(),
101
+                'title' => $widget->getTitle(),
102
+                'iconClass' => $widget->getIconClass(),
103
+                'url' => $widget->getUrl()
104
+            ];
105
+        }, $this->dashboardManager->getWidgets());
106
+        $this->inititalStateService->provideInitialState('dashboard', 'panels', $widgets);
107
+        $this->inititalStateService->provideInitialState('dashboard', 'layout', $userLayout);
108
+        $this->inititalStateService->provideInitialState('dashboard', 'firstRun', $this->config->getUserValue($this->userId, 'dashboard', 'firstRun', '1') === '1');
109
+        $this->inititalStateService->provideInitialState('dashboard', 'shippedBackgrounds', BackgroundService::SHIPPED_BACKGROUNDS);
110
+        $this->inititalStateService->provideInitialState('dashboard', 'background', $this->config->getUserValue($this->userId, 'dashboard', 'background', 'default'));
111
+        $this->inititalStateService->provideInitialState('dashboard', 'version', $this->config->getUserValue($this->userId, 'dashboard', 'backgroundVersion', 0));
112
+        $this->config->setUserValue($this->userId, 'dashboard', 'firstRun', '0');
113 113
 
114
-		return new TemplateResponse('dashboard', 'index');
115
-	}
114
+        return new TemplateResponse('dashboard', 'index');
115
+    }
116 116
 
117
-	/**
118
-	 * @NoAdminRequired
119
-	 * @param string $layout
120
-	 * @return JSONResponse
121
-	 */
122
-	public function updateLayout(string $layout): JSONResponse {
123
-		$this->config->setUserValue($this->userId, 'dashboard', 'layout', $layout);
124
-		return new JSONResponse(['layout' => $layout]);
125
-	}
117
+    /**
118
+     * @NoAdminRequired
119
+     * @param string $layout
120
+     * @return JSONResponse
121
+     */
122
+    public function updateLayout(string $layout): JSONResponse {
123
+        $this->config->setUserValue($this->userId, 'dashboard', 'layout', $layout);
124
+        return new JSONResponse(['layout' => $layout]);
125
+    }
126 126
 
127
-	/**
128
-	 * @NoAdminRequired
129
-	 */
130
-	public function setBackground(string $type, string $value): JSONResponse {
131
-		$currentVersion = (int)$this->config->getUserValue($this->userId, 'dashboard', 'backgroundVersion', 0);
132
-		try {
133
-			switch ($type) {
134
-				case 'shipped':
135
-					$this->backgroundService->setShippedBackground($value);
136
-					break;
137
-				case 'custom':
138
-					$this->backgroundService->setFileBackground($value);
139
-					break;
140
-				case 'color':
141
-					$this->backgroundService->setColorBackground($value);
142
-					break;
143
-				case 'default':
144
-					$this->backgroundService->setDefaultBackground();
145
-					break;
146
-				default:
147
-					return new JSONResponse(['error' => 'Invalid type provided'], Http::STATUS_BAD_REQUEST);
148
-			}
149
-		} catch (\InvalidArgumentException $e) {
150
-			return new JSONResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST);
151
-		} catch (\Throwable $e) {
152
-			return new JSONResponse(['error' => $e->getMessage()], Http::STATUS_INTERNAL_SERVER_ERROR);
153
-		}
154
-		$currentVersion++;
155
-		$this->config->setUserValue($this->userId, 'dashboard', 'backgroundVersion', (string)$currentVersion);
156
-		return new JSONResponse([
157
-			'type' => $type,
158
-			'value' => $value,
159
-			'version' => $this->config->getUserValue($this->userId, 'dashboard', 'backgroundVersion', $currentVersion)
160
-		]);
161
-	}
127
+    /**
128
+     * @NoAdminRequired
129
+     */
130
+    public function setBackground(string $type, string $value): JSONResponse {
131
+        $currentVersion = (int)$this->config->getUserValue($this->userId, 'dashboard', 'backgroundVersion', 0);
132
+        try {
133
+            switch ($type) {
134
+                case 'shipped':
135
+                    $this->backgroundService->setShippedBackground($value);
136
+                    break;
137
+                case 'custom':
138
+                    $this->backgroundService->setFileBackground($value);
139
+                    break;
140
+                case 'color':
141
+                    $this->backgroundService->setColorBackground($value);
142
+                    break;
143
+                case 'default':
144
+                    $this->backgroundService->setDefaultBackground();
145
+                    break;
146
+                default:
147
+                    return new JSONResponse(['error' => 'Invalid type provided'], Http::STATUS_BAD_REQUEST);
148
+            }
149
+        } catch (\InvalidArgumentException $e) {
150
+            return new JSONResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST);
151
+        } catch (\Throwable $e) {
152
+            return new JSONResponse(['error' => $e->getMessage()], Http::STATUS_INTERNAL_SERVER_ERROR);
153
+        }
154
+        $currentVersion++;
155
+        $this->config->setUserValue($this->userId, 'dashboard', 'backgroundVersion', (string)$currentVersion);
156
+        return new JSONResponse([
157
+            'type' => $type,
158
+            'value' => $value,
159
+            'version' => $this->config->getUserValue($this->userId, 'dashboard', 'backgroundVersion', $currentVersion)
160
+        ]);
161
+    }
162 162
 
163
-	/**
164
-	 * @NoAdminRequired
165
-	 * @NoCSRFRequired
166
-	 */
167
-	public function getBackground() {
168
-		$file = $this->backgroundService->getBackground();
169
-		if ($file !== null) {
170
-			$response = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => $file->getMimeType()]);
171
-			$response->cacheFor(24 * 60 * 60);
172
-			return $response;
173
-		}
174
-		return new NotFoundResponse();
175
-	}
163
+    /**
164
+     * @NoAdminRequired
165
+     * @NoCSRFRequired
166
+     */
167
+    public function getBackground() {
168
+        $file = $this->backgroundService->getBackground();
169
+        if ($file !== null) {
170
+            $response = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => $file->getMimeType()]);
171
+            $response->cacheFor(24 * 60 * 60);
172
+            return $response;
173
+        }
174
+        return new NotFoundResponse();
175
+    }
176 176
 }
Please login to merge, or discard this patch.
apps/dashboard/lib/Controller/LayoutApiController.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -33,31 +33,31 @@
 block discarded – undo
33 33
 
34 34
 class LayoutApiController extends OCSController {
35 35
 
36
-	/** @var IConfig */
37
-	private $config;
38
-	/** @var string */
39
-	private $userId;
40
-
41
-	public function __construct(
42
-		string $appName,
43
-		IRequest $request,
44
-		IConfig $config,
45
-		$userId
46
-	) {
47
-		parent::__construct($appName, $request);
48
-
49
-		$this->config = $config;
50
-		$this->userId = $userId;
51
-	}
52
-
53
-	/**
54
-	 * @NoAdminRequired
55
-	 *
56
-	 * @param string $layout
57
-	 * @return JSONResponse
58
-	 */
59
-	public function create(string $layout): JSONResponse {
60
-		$this->config->setUserValue($this->userId, 'dashboard', 'layout', $layout);
61
-		return new JSONResponse(['layout' => $layout]);
62
-	}
36
+    /** @var IConfig */
37
+    private $config;
38
+    /** @var string */
39
+    private $userId;
40
+
41
+    public function __construct(
42
+        string $appName,
43
+        IRequest $request,
44
+        IConfig $config,
45
+        $userId
46
+    ) {
47
+        parent::__construct($appName, $request);
48
+
49
+        $this->config = $config;
50
+        $this->userId = $userId;
51
+    }
52
+
53
+    /**
54
+     * @NoAdminRequired
55
+     *
56
+     * @param string $layout
57
+     * @return JSONResponse
58
+     */
59
+    public function create(string $layout): JSONResponse {
60
+        $this->config->setUserValue($this->userId, 'dashboard', 'layout', $layout);
61
+        return new JSONResponse(['layout' => $layout]);
62
+    }
63 63
 }
Please login to merge, or discard this patch.
apps/dashboard/appinfo/routes.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -25,10 +25,10 @@
 block discarded – undo
25 25
  */
26 26
 
27 27
 return [
28
-	'routes' => [
29
-		['name' => 'dashboard#index', 'url' => '/', 'verb' => 'GET'],
30
-		['name' => 'dashboard#updateLayout', 'url' => '/layout', 'verb' => 'POST'],
31
-		['name' => 'dashboard#getBackground', 'url' => '/background', 'verb' => 'GET'],
32
-		['name' => 'dashboard#setBackground', 'url' => '/background/{type}', 'verb' => 'POST'],
33
-	]
28
+    'routes' => [
29
+        ['name' => 'dashboard#index', 'url' => '/', 'verb' => 'GET'],
30
+        ['name' => 'dashboard#updateLayout', 'url' => '/layout', 'verb' => 'POST'],
31
+        ['name' => 'dashboard#getBackground', 'url' => '/background', 'verb' => 'GET'],
32
+        ['name' => 'dashboard#setBackground', 'url' => '/background/{type}', 'verb' => 'POST'],
33
+    ]
34 34
 ];
Please login to merge, or discard this patch.