Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP:allow the user to specify the day the weeks starts #335

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions controller/settingscontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public function getConfig($key) {
return $this->getShowWeekNr();
case 'firstRun':
return $this->getFirstRun();
case 'startOfWeek':
return $this->getStartOfWeek();
default:
return new JSONResponse([], Http::STATUS_BAD_REQUEST);
}
Expand All @@ -101,6 +103,8 @@ public function setConfig($key, $value) {
return $this->setShowWeekNr($value);
case 'firstRun':
return $this->setFirstRun();
case 'startOfWeek':
return $this->setStartOfWeek($value);
default:
return new JSONResponse([], Http::STATUS_BAD_REQUEST);
}
Expand Down Expand Up @@ -280,6 +284,49 @@ private function getShowWeekNr() {
]);
}

/**
* set config value for start of week
*
* @param $value
* @return JSONResponse
*/
private function setStartOfWeek($value) {
try {
$this->config->setUserValue(
$this->userId,
$this->appName,
'startOfWeek',
$value
);
} catch(\Exception $e) {
return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR);
}

return new JSONResponse();
}

/**
* get config value for start of week
*
* @return JSONResponse
*/
private function getStartOfWeek() {
try {
$value = $this->config->getUserValue(
$this->userId,
$this->appName,
'startOfWeek',
''
);
} catch(\Exception $e) {
return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR);
}

return new JSONResponse([
'value' => $value,
]);
}

/**
* check if value for showWeekNr is allowed
*
Expand Down
2 changes: 2 additions & 0 deletions controller/viewcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public function index() {
$initialView = $this->config->getUserValue($userId, $this->appName, 'currentView', null);
$skipPopover = $this->config->getUserValue($userId, $this->appName, 'skipPopover', 'no');
$weekNumbers = $this->config->getUserValue($userId, $this->appName, 'showWeekNr', 'no');
$startOfWeek = $this->config->getUserValue($userId, $this->appName, 'startOfWeek', '');
$firstRun = $this->config->getUserValue($userId, $this->appName, 'firstRun', null);
$defaultColor = $this->config->getAppValue('theming', 'color', '#0082C9');

Expand Down Expand Up @@ -118,6 +119,7 @@ public function index() {
'emailAddress' => $emailAddress,
'skipPopover' => $skipPopover,
'weekNumbers' => $weekNumbers,
'startOfWeek' => $startOfWeek,
'firstRun' => $firstRun,
'supportsClass' => $supportsClass,
'defaultColor' => $defaultColor,
Expand Down
12 changes: 12 additions & 0 deletions js/app/controllers/settingscontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,17 @@ app.controller('SettingsController', ['$scope', '$uibModal', '$timeout', 'Settin
fc.elm.fullCalendar('option', 'weekNumbers', (newValue === 'yes'));
}
};

$scope.updateStartOfWeek = function() {
let newValue = $scope.settingsStartOfWeek;
settings.startOfWeek = newValue;
SettingsService.setStartOfWeek(newValue);
if (newValue === '') {
newValue = +moment().startOf('week').format('d');
}
if (fc.elm) {
fc.elm.fullCalendar('option', 'firstDay', newValue);
}
};
}
]);
23 changes: 23 additions & 0 deletions js/app/service/settingsservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,29 @@ app.service('SettingsService', ['$rootScope', '$http', function($rootScope, $htt
});
};

this.getStartOfWeek = function() {
return $http({
method: 'GET',
url: $rootScope.baseUrl + 'config',
params: {key: 'startOfWeek'}
}).then(function(response) {
return response.data.value;
});
};

this.setStartOfWeek = function(value) {
return $http({
method: 'POST',
url: $rootScope.baseUrl + 'config',
data: {
key: 'startOfWeek',
value: value
}
}).then(function() {
return true;
});
};

this.passedFirstRun = function() {
return $http({
method: 'POST',
Expand Down
1 change: 1 addition & 0 deletions templates/part.fullcalendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class="calendar"
data-firstRun="<?php p($_['firstRun']); ?>"
data-skipPopover="<?php p($_['skipPopover']); ?>"
data-weekNumbers="<?php p($_['weekNumbers']); ?>"
data-startOfWeek="<?php p($_['startOfWeek']); ?>"
data-webCalWorkaround="<?php p($_['webCalWorkaround']); ?>"
data-isPublic="<?php p($_['isPublic'] ? '1' : '0'); ?>"
fc
Expand Down
15 changes: 15 additions & 0 deletions templates/part.settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ class="settings-button"
<?php p($l->t('Show week numbers')); ?>
</label>
</li>
<li class="settings-fieldset-interior-item settings-fieldset-interior-startofweek">
<label for="show_startofweek_select">
<?php p($l->t('Start of week')); ?>
</label>
<select class="checkbox" type="checkbox" ng-change="updateStartOfWeek()" ng-model="settingsStartOfWeek" id="show_startofweek_select">
<option value=""><?php p($l->t('From language')); ?></option>
<option value="1"><?php p($l->t('Monday')); ?></option>
<option value="2"><?php p($l->t('Tuesday')); ?></option>
<option value="3"><?php p($l->t('Wednesday')); ?></option>
<option value="4"><?php p($l->t('Thursday')); ?></option>
<option value="5"><?php p($l->t('Friday')); ?></option>
<option value="6"><?php p($l->t('Saturday')); ?></option>
<option value="0"><?php p($l->t('Sunday')); ?></option>
</select>
</li>
<li class="settings-fieldset-interior-item settings-fieldset-interior-upload">
<input type="file" name="file" accept="text/calendar" multiple id="import" />
<span href="#" class="settings-upload svg icon-upload" role="button" id="import-button-overlay"><?php p($l->t('Import calendar')); ?></span>
Expand Down
23 changes: 23 additions & 0 deletions tests/js/unit/services/settingsServiceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,29 @@ describe('Settings Service', function () {
expect(http.flush).not.toThrow();
});

it ('should set the startOfWeek value', function() {
http.expect('POST', 'fancy-url/config', {
'key': 'startOfWeek',
'value': '3'
}).respond(200, {value: '3'});

SettingsService.setStartOfWeek('3').then(function(result) {
expect(result).toBe(true);
});

expect(http.flush).not.toThrow();
});

it ('should get the startOfWeek value', function() {
http.expect('GET', 'fancy-url/config?key=startOfWeek').respond(200, {value: '2'});

SettingsService.getStartOfWeek().then(function(result) {
expect(result).toEqual('2');
});

expect(http.flush).not.toThrow();
});

it ('should tell the server about the first run', function() {
http.expect('POST', 'fancy-url/config', {
'key': 'firstRun'
Expand Down