ApplicationModel constructor

ApplicationModel(
  1. Model parent, {
  2. String? key,
  3. required String url,
  4. String? title,
  5. int? page,
  6. int? order,
  7. Map<String, dynamic>? settings,
})

Implementation

ApplicationModel(Model parent,
    {String? key,
      required String url,
      this.title,
      this.page,
      this.order,
      Map<String,dynamic>? settings})
    : super(parent, myId, scope: Scope(id: myId)) {

  // parse to url into its parts
  Uri? uri = Uri.tryParse(url);
  if (uri == null) return;

  // no scheme provided
  if (!uri.hasScheme) uri = Uri.tryParse("https://${uri.url}");
  if (uri == null) return;

  // file uri - must start in the applications root
  if (uri.scheme == "file") {
    var host = uri.host;
    if (host.toLowerCase().trim() != "applications") {
      var url = uri.url.replaceFirst(host, "applications/$host");
      uri = Uri.tryParse(url);
      if (uri == null) return;
    }
  }

  // set the url
  this.url = uri.removeEmptySegments().url;

  // set database key
  _dbKey = key ?? this.url;

  // set the scheme and host
  _scheme = uri.scheme;
  _host = uri.host;

  // set the start page
  String? fragment = uri.hasFragment ? uri.fragment : null;
  if (fragment != null && fragment.toLowerCase().contains(".xml")) {
    var myUri = Uri.tryParse(fragment);
    if (myUri != null) {
      _queryParameters = myUri.hasQuery ? myUri.queryParameters : null;
      _startPage = myUri.removeQuery().url;
    }
  } else {
    _queryParameters = uri.queryParameters;
  }

  // base domain
  _domain = uri
      .removeFragment()
      .removeQuery()
      .replace(userInfo: null)
      .removeEmptySegments()
      .url;

  // initialize the config
  if (settings != null) _config = ConfigModel.fromMap(settings);

  // set active user
  var jwt = setting("jwt");
  _user = UserModel(this, jwt: jwt);

  // load the config
  initialize();
}