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

Fix Dataset Configurations #4845

Merged
merged 51 commits into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
27af731
change getting of dataset configurations
grittaweisheit Sep 30, 2020
f98f2d1
[WIP] backend split layer and dataset config handling
Sep 30, 2020
31bbc1f
clean up frontend
grittaweisheit Oct 1, 2020
be446f6
add evolutions
Oct 1, 2020
b0c1066
merge master
Oct 1, 2020
aa6be99
fix frontend linting
Oct 1, 2020
fd7cf89
fix frontend tests
Oct 2, 2020
0528ed1
fix frontend tests 2
Oct 2, 2020
37da2ae
pretty frontend
Oct 2, 2020
4c2cdf4
update changelog and migrations guide
Oct 5, 2020
59f80a9
Apply suggestions from code review
youri-k Oct 5, 2020
9f54474
remove unnecessary invalidation of user
Oct 5, 2020
644ff27
Merge branch 'fix-dataset-configurations' of github.com:scalableminds…
Oct 5, 2020
065cf37
apply pr feedback
Oct 7, 2020
51bbca3
Merge branch 'master' into fix-dataset-configurations
youri-k Oct 8, 2020
58cafc5
check for volume ids when no config is found
Oct 9, 2020
44343d9
Merge branch 'fix-dataset-configurations' of github.com:scalableminds…
Oct 9, 2020
c469d1b
rename default view config to unify wk and datastore implementation
Oct 12, 2020
7818a06
rename backend types to match each other
Oct 13, 2020
eaf5081
Merge branch 'master' of github.com:scalableminds/webknossos into fix…
Oct 13, 2020
039d0a5
Merge branch 'master' of github.com:scalableminds/webknossos into fix…
Oct 14, 2020
4d100a4
add frontend part to validate DatasetConfiguration
Oct 14, 2020
667c8be
fix evolution after renaming
Oct 14, 2020
1b07231
move type and schema definitions
Oct 14, 2020
6f36e65
fix e2e tests
Oct 14, 2020
cc3c2d0
move datasource types
Oct 15, 2020
bdffbbe
update snapshots
Oct 15, 2020
5c2f2e9
run eliminate errors always because it checks for errors
Oct 15, 2020
dee2ecd
enforce validated configuration in api instead of model_initialization
philippotto Oct 15, 2020
8aaaabb
use new validation for dataset import as well
Oct 15, 2020
8981f57
fix frontend tests
Oct 15, 2020
ece440c
Merge branch 'master' of github.com:scalableminds/webknossos into fix…
Oct 15, 2020
ec89820
add table for layer view configurations
Oct 15, 2020
01941fc
fix for null values
Oct 15, 2020
1c65001
fix frontend test
Oct 15, 2020
1fda7f6
add additional frontend tests
Oct 16, 2020
fbfec83
fix pretty
Oct 16, 2020
ff52183
reversion of evolution
Oct 16, 2020
ab42998
rework update layers
Oct 16, 2020
bfc8f39
fix naming in reversion of evolution
Oct 16, 2020
8453954
update documentation
Oct 16, 2020
2939900
fix documentation
Oct 16, 2020
a3fa8e8
rename methods to new naming schema
Oct 19, 2020
6c55777
Merge branch 'master' of github.com:scalableminds/webknossos into fix…
Oct 20, 2020
7a74654
pr feedback
Oct 20, 2020
beb7411
merge master
Oct 26, 2020
2e9219a
bump schema version
Oct 26, 2020
526a75a
fix version number in evolution
Oct 26, 2020
22c66b2
Merge branch 'master' into fix-dataset-configurations
youri-k Oct 26, 2020
2b5562c
Merge branch 'master' into fix-dataset-configurations
youri-k Oct 28, 2020
b02021e
Merge branch 'master' into fix-dataset-configurations
youri-k Oct 28, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released

### Fixed
- Fixed failing histogram requests for float layers with NaN values. [#4834](https://github.com/scalableminds/webknossos/pull/4834)
- Fixed the disappearing of dataset settings after switching between view mode and annotation mode. [#4845](https://github.com/scalableminds/webknossos/pull/4845)

### Removed
-
2 changes: 1 addition & 1 deletion MIGRATIONS.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ User-facing changes are documented in the [changelog](CHANGELOG.released.md).
-

### Postgres Evolutions:
-
- [056-add-layer-specific-view-configs.sql](conf/evolutions/056-add-layer-specific-view-configs.sql)
91 changes: 42 additions & 49 deletions app/controllers/ConfigurationController.scala
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
package controllers

import com.scalableminds.util.accesscontext.{DBAccessContext, GlobalAccessContext}
import com.mohiva.play.silhouette.api.Silhouette
import com.scalableminds.util.accesscontext.GlobalAccessContext
import com.scalableminds.util.tools.Fox
import javax.inject.Inject
import models.binary.{DataSet, DataSetDAO, DataSetService}
import models.configuration.{DataSetConfiguration, DataSetConfigurationDefaults, UserConfiguration}
import models.user.{UserDataSetConfigurationDAO, UserService}
import models.configuration.{DataSetConfigurationService, UserConfiguration}
import models.user.{UserDataSetConfigurationDAO, UserDataSetLayerConfigurationDAO, UserService}
import oxalis.security.WkEnv
import com.mohiva.play.silhouette.api.Silhouette
import com.mohiva.play.silhouette.api.actions.{SecuredRequest, UserAwareRequest}
import play.api.i18n.{Messages, MessagesApi}
import play.api.libs.json.{JsObject, JsValue}
import play.api.i18n.Messages
import play.api.libs.json.{JsObject}
import play.api.libs.json.Json._
import play.api.mvc.PlayBodyParsers

import scala.concurrent.ExecutionContext

class ConfigurationController @Inject()(userService: UserService,
dataSetService: DataSetService,
dataSetDAO: DataSetDAO,
userDataSetConfigurationDAO: UserDataSetConfigurationDAO,
dataSetConfigurationDefaults: DataSetConfigurationDefaults,
sil: Silhouette[WkEnv])(implicit ec: ExecutionContext)
class ConfigurationController @Inject()(
userService: UserService,
dataSetService: DataSetService,
dataSetDAO: DataSetDAO,
dataSetConfigurationService: DataSetConfigurationService,
sil: Silhouette[WkEnv])(implicit ec: ExecutionContext, bodyParsers: PlayBodyParsers)
extends Controller {

def read = sil.UserAwareAction.async { implicit request =>
Expand All @@ -41,57 +41,50 @@ class ConfigurationController @Inject()(userService: UserService,
}
}

def readDataSet(organizationName: String, dataSetName: String) = sil.UserAwareAction.async { implicit request =>
request.identity.toFox.flatMap { user =>
for {
configurationJson: JsValue <- userDataSetConfigurationDAO.findOneForUserAndDataset(user._id, dataSetName)
} yield DataSetConfiguration(configurationJson.validate[Map[String, JsValue]].getOrElse(Map.empty))
}.orElse(
for {
dataSet <- dataSetDAO.findOneByNameAndOrganizationName(dataSetName, organizationName)(GlobalAccessContext)
config <- dataSetConfigurationDefaults.constructInitialDefault(dataSet)
} yield config
)
.getOrElse(dataSetConfigurationDefaults.constructInitialDefault(List()))
.map(configuration => Ok(toJson(dataSetConfigurationDefaults.configurationOrDefaults(configuration))))
}
def readDataSetViewConfiguration(organizationName: String, dataSetName: String) =
sil.UserAwareAction.async(validateJson[List[String]]) { implicit request =>
request.identity.toFox
.flatMap(user =>
dataSetConfigurationService
.getDataSetViewConfigurationForUserAndDataset(request.body, user, dataSetName, organizationName))
.orElse(
dataSetConfigurationService.getDataSetViewConfigurationForDataset(request.body, dataSetName, organizationName)
)
.getOrElse(Map.empty)
.map(configuration => Ok(toJson(configuration)))
}

def updateDataSet(organizationName: String, dataSetName: String) =
def updateDataSetViewConfiguration(organizationName: String, dataSetName: String) =
sil.SecuredAction.async(parse.json(maxLength = 20480)) { implicit request =>
for {
jsConfiguration <- request.body.asOpt[JsObject] ?~> "user.configuration.dataset.invalid"
conf = jsConfiguration.fields.toMap
_ <- userService.updateDataSetConfiguration(request.identity,
dataSetName,
organizationName,
DataSetConfiguration(conf))
dataSetConf = conf - "layers"
layerConf = conf.get("layers")
_ <- userService.updateDataSetViewConfiguration(request.identity,
dataSetName,
organizationName,
dataSetConf,
layerConf)
} yield {
JsonOk(Messages("user.configuration.dataset.updated"))
}
}

def readDataSetDefault(organizationName: String, dataSetName: String) = sil.SecuredAction.async { implicit request =>
dataSetDAO.findOneByNameAndOrganization(dataSetName, request.identity._organization).flatMap { dataSet: DataSet =>
dataSet.defaultConfiguration match {
case Some(c) =>
Fox.successful(
Ok(toJson(dataSetConfigurationDefaults.configurationOrDefaults(c, dataSet.sourceDefaultConfiguration))))
case _ =>
dataSetConfigurationDefaults
.constructInitialDefault(dataSet)
.map(c => Ok(toJson(dataSetConfigurationDefaults.configurationOrDefaults(c))))
}
}
def readDataSetAdminViewConfiguration(organizationName: String, dataSetName: String) = sil.SecuredAction.async {
implicit request =>
dataSetConfigurationService
.getCompleteAdminViewConfiguration(dataSetName, organizationName)
.map(configuration => Ok(toJson(configuration)))
}

def updateDataSetDefault(organizationName: String, dataSetName: String) =
def updateDataSetAdminViewConfiguration(organizationName: String, dataSetName: String) =
sil.SecuredAction.async(parse.json(maxLength = 20480)) { implicit request =>
for {
dataset <- dataSetDAO.findOneByNameAndOrganization(dataSetName, request.identity._organization) ?~> "dataset.notFound" ~> NOT_FOUND
dataset <- dataSetDAO.findOneByNameAndOrganizationName(dataSetName, organizationName) ?~> "dataset.notFound" ~> NOT_FOUND
_ <- dataSetService.isEditableBy(dataset, Some(request.identity)) ?~> "notAllowed" ~> FORBIDDEN
jsConfiguration <- request.body.asOpt[JsObject] ?~> "user.configuration.dataset.invalid"
conf = jsConfiguration.fields.toMap
_ <- dataSetDAO.updateDefaultConfigurationByName(dataSetName, DataSetConfiguration(conf))
jsObject <- request.body.asOpt[JsObject].toFox ?~> "user.configuration.dataset.invalid"
_ <- dataSetConfigurationService.updateAdminViewConfigurationFor(dataset, jsObject.fields.toMap)
} yield {
JsonOk(Messages("user.configuration.dataset.updated"))
}
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/DataSetController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ class DataSetController @Inject()(userService: UserService,
case Some(a) =>
Fox.successful(a)
case _ => {
val defaultCenterOpt = dataSet.defaultConfiguration.flatMap(c =>
c.configuration.get("position").flatMap(jsValue => JsonHelper.jsResultToOpt(jsValue.validate[Point3D])))
val defaultZoomOpt = dataSet.defaultConfiguration.flatMap(c =>
c.configuration.get("zoom").flatMap(jsValue => JsonHelper.jsResultToOpt(jsValue.validate[Double])))
val defaultCenterOpt = dataSet.adminViewConfiguration.flatMap(c =>
c.get("position").flatMap(jsValue => JsonHelper.jsResultToOpt(jsValue.validate[Point3D])))
val defaultZoomOpt = dataSet.adminViewConfiguration.flatMap(c =>
c.get("zoom").flatMap(jsValue => JsonHelper.jsResultToOpt(jsValue.validate[Double])))
dataSetService
.clientFor(dataSet)
.flatMap(
Expand Down
Loading