Skip to content

Commit

Permalink
Adding locations
Browse files Browse the repository at this point in the history
  • Loading branch information
José Redrejo committed Nov 11, 2022
1 parent 36c767d commit bdde663
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 73 deletions.
6 changes: 3 additions & 3 deletions kolibri/core/device/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ def create(self, validated_data):
class DeviceSettingsSerializer(DeviceSerializerMixin, serializers.ModelSerializer):

extra_settings = serializers.JSONField(required=False)
primary_storage_location = serializers.CharField(required=True)
primary_storage_location = serializers.CharField(required=False)
secondary_storage_locations = serializers.ListField(
child=serializers.CharField(), required=False
child=serializers.CharField(required=False), required=False
)

class Meta:
Expand Down Expand Up @@ -182,7 +182,7 @@ def validate(self, data):
if not check_is_directory(path):
raise serializers.ValidationError(
{
"secondary_storage_locations": "Primary storage location must be a directory"
"secondary_storage_locations": "Secondary storage location must be a directory"
}
)
return data
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
:title="$tr('newStorageLocation')"
:submitText="coreString('continueAction')"
:cancelText="coreString('cancelAction')"
:submitDisabled="submitDisabled"
@submit="handleSubmit"
@cancel="$emit('cancel')"
>
Expand All @@ -15,8 +14,8 @@
type="text"
:label="$tr('filePath')"
:invalid="invalidPath"
:invalidText="$tr('error')"
showInvalidText="true"
:invalidText="showError"
:showInvalidText="true"
@input="invalidPath = false"
/>
</KModal>
Expand All @@ -32,19 +31,43 @@
export default {
name: 'AddStorageLocationModal',
mixins: [commonCoreStrings],
props: {
paths: {
type: Array,
required: true,
},
},
data() {
return {
path: null,
invalidPath: false,
errorType: null,
};
},
computed: {
showError() {
if (this.errorType === 'directory') {
return this.$tr('errorInvalidFolder');
} else {
return this.$tr('errorExistingFolder');
}
},
},
methods: {
handleSubmit() {
getPathPermissions(this.path).then(permissions => {
const writable = permissions.data.writable;
const exists = this.paths.filter(el => el.path === this.path);
if (exists.length > 0) {
this.invalidPath = true;
this.errorType = 'exists';
return;
}
this.invalidPath = !permissions.data.directory;
if (permissions.data.directory) {
this.$emit('submit', this.path, writable);
} else {
this.errorType = 'directory';
}
});
},
Expand All @@ -63,8 +86,12 @@
message: 'File path',
context: 'Label for new storage location input',
},
error: {
message: 'Invalid path',
errorInvalidFolder: {
message: 'This is not a valid folder in the server',
context: 'Error text for new storage location input',
},
errorExistingFolder: {
message: 'This folder is already in the list of storage locations',
context: 'Error text for new storage location input',
},
},
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,22 @@
:title="$tr('serverRestart')"
:submitText="coreString('continueAction')"
:cancelText="coreString('cancelAction')"
@submit="$emit('submit')"
@submit="handleSubmit"
@cancel="$emit('cancel')"
>
<p>{{ $tr('serverRestartDecription', { changedSetting: changedSetting }) }}</p>
<p v-if="changedSetting === 'primary'">
{{ $tr('selectedPath', { path: path.name }) }}
</p>
<p>{{ getMessage() }}</p>
<div v-if="changedSetting === 'primary'">
<KCheckbox
:checked="confirmationChecked"
:label="$tr('makePrimary')"
/>
<p :style="{ color: $themeTokens.textDisabled }">
{{ $tr('labelPrimary') }}
</p>
</div>
</KModal>

</template>
Expand All @@ -22,20 +34,75 @@
mixins: [commonCoreStrings],
props: {
changedSetting: {
type: String,
type: String, // primary, remove, add
required: true,
},
path: {
type: Object,
required: false,
default: null,
},
},
data() {
return {
confirmationChecked: false,
};
},
methods: {
getMessage() {
let message = '';
if (this.changedSetting === 'primary') {
message = this.$tr('newPrimaryLocationRestartDescription');
} else if (this.changedSetting === 'remove') {
message = this.$tr('removeLocationRestartDescription');
} else if (this.changedSetting === 'add') {
message = this.$tr('newLocationRestartDescription');
}
return message + this.$tr('serverRestartDecription');
},
handleSubmit() {
if (this.changedSetting === 'primary') {
this.$emit('submit', this.confirmationChecked);
} else {
this.$emit('submit');
}
},
},
$trs: {
serverRestart: {
message: 'Server restart',
context: 'Prompt for removing a storage location.',
},
newLocationRestartDescription: {
message: 'Server needs to restart to add a new storage location.',
context: 'Reason to restart the server.',
},
newPrimaryLocationRestartDescription: {
message: 'Changing the primary storage location will restart this server.',
context: 'Reason to restart the server.',
},
removeLocationRestartDescription: {
message: 'Removing a storage location will restart this server.',
context: 'Reason to restart the server.',
},
serverRestartDecription: {
message:
'{changedSetting} restart this server. Anyone using Kolibri on this server right now will temporarily be unable to use it.',
' Anyone using Kolibri on this server right now will temporarily be unable to use it.',
context: 'Description for restarting the server.',
},
selectedPath: {
message: 'Selected: {path}',
context: 'Label for the selected path.',
},
makePrimary: {
message: 'Make this the primary storage location',
context: 'Checkbox to make primary storage location.',
},
labelPrimary: {
message: 'Newly downloaded resources will be added to the primary storage location',
context: 'Label for primary storage location.',
},
},
};
Expand Down
10 changes: 10 additions & 0 deletions kolibri/plugins/device/assets/src/views/DeviceSettingsPage/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,13 @@ export function getPathPermissions(path) {
params: { path },
});
}

export function getPathsPermissions(paths) {
let pathsInfo = [];
for (let path of paths) {
getPathPermissions(path).then(permissions => {
pathsInfo.push({ path, writable: permissions.data.writable });
});
}
return pathsInfo;
}
Loading

0 comments on commit bdde663

Please sign in to comment.