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(services): namespace all services #653

Merged
merged 1 commit into from
Jan 3, 2024
Merged
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
34 changes: 20 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ constructor(...args) {
"session",
"intl",
"notification",
{ config: "alexandria-config" },
"alexandria-config",
],
},
},
Expand All @@ -63,8 +63,8 @@ meta value for a model should be. Each configuration field is scoped by model na
(check out the example to understand what is meant by this).

For this you need to create a service extending from
`ember-alexandria/services/config` which you then have to pass as `config` to
alexandria.
`ember-alexandria/services/alexandria-config` which you then have to pass as
`alexandria-config` to alexandria.

This is needed since an engine does not merge its env into the host apps.
See https://github.com/ember-engines/ember-engines/issues/176 for more info.
Expand All @@ -81,9 +81,9 @@ can ignore the getters and just define the field as usual.
**Example**:

```js
import ConfigService from "ember-alexandria/services/config";
import AlexandriaConfigService from "ember-alexandria/services/alexandria-config";

export default class AlexandriaConfigService extends ConfigService {
export default class CustomAlexandriaConfigService extends AlexandriaConfigService {
get modelMetaFilters() {
return {
document: [
Expand Down Expand Up @@ -122,17 +122,22 @@ With it you for example fetch the users and groups of the documents in a batch.
**Example**:

```js
import ConfigService from "ember-alexandria/services/config";
import AlexandriaConfigService from "ember-alexandria/services/alexandria-config";
import { inject as service } from "@ember/service";

export default class AlexandriaConfigService extends ConfigService {
export default class CustomAlexandriaConfigService extends AlexandriaConfigService {
@service store;

activeUser = 1;
activeGroup = 1;

resolveUser(id) { return this.store.peekRecord("user", id); }
resolveGroup(id) { return this.store.peekRecord("group", id); }
resolveUser(id) {
return this.store.peekRecord("user", id);
}

resolveGroup(id) {
return this.store.peekRecord("group", id);
}

documentsPostProcess(documents) {
const users = documents.map((d) => d.createdByUser);
Expand All @@ -141,7 +146,7 @@ export default class AlexandriaConfigService extends ConfigService {
this.store.query("user", { filter: { id: users.join(",") } });
this.store.query("group", { filter: { id: groups.join(",") } });

return documents
return documents;
}
}
```
Expand All @@ -155,16 +160,17 @@ Additionally to tags you can configure marks. Marks are similar to tags, but are
The icons for marks are from [FontAwesome](https://fontawesome.com/search?o=r&m=free&s=regular%2Csolid).

The object for a mark has the following properties:

- `type`: This is the id of a tag used to identify the mark in the backend.
- `icon`: This a string, which references an FontAwesome.
- `tooltip`: This is shown when hovering over the mark.

An example configuration with two icons might look like this:

```js
import ConfigService from "ember-alexandria/services/config";
import AlexandriaConfigService from "ember-alexandria/services/alexandria-config";

export default class AlexandriaConfigService extends ConfigService {
export default class CustomAlexandriaConfigService extends AlexandriaConfigService {
get marks() {
return [
{
Expand All @@ -183,6 +189,7 @@ export default class AlexandriaConfigService extends ConfigService {
```

Configure used icons in `config/icons.js`

```js
module.exports = function () {
return {
Expand All @@ -191,7 +198,6 @@ module.exports = function () {
};
```


## Contributing

See the [Contributing](CONTRIBUTING.md) guide for details.
Expand Down
2 changes: 1 addition & 1 deletion addon/adapters/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { inject as service } from "@ember/service";
import OIDCJSONAPIAdapter from "ember-simple-auth-oidc/adapters/oidc-json-api-adapter";

export default class ApplicationAdapter extends OIDCJSONAPIAdapter {
@service config;
@service("alexandria-config") config;
@service session;

get namespace() {
Expand Down
2 changes: 1 addition & 1 deletion addon/components/category-nav/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";

export default class CategoryNavCategoryComponent extends Component {
@service documents;
@service("alexandria-documents") documents;
@service router;

@tracked collapseChildren = false;
Expand Down
2 changes: 1 addition & 1 deletion addon/components/document-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ErrorHandler } from "ember-alexandria/helpers/error-handler";
export default class DocumentCardComponent extends Component {
@service notification;
@service intl;
@service config;
@service("alexandria-config") config;

get classes() {
const classes = [
Expand Down
2 changes: 1 addition & 1 deletion addon/components/document-delete-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ErrorHandler } from "ember-alexandria/helpers/error-handler";
export default class DocumentDeleteButtonComponent extends Component {
@service notification;
@service intl;
@service documents;
@service("alexandria-documents") documents;
@service router;

@tracked dialogVisible = false;
Expand Down
2 changes: 1 addition & 1 deletion addon/components/document-upload-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class DocumentUploadButtonComponent extends Component {
@service notification;
@service intl;
@service store;
@service documents;
@service("alexandria-documents") documents;

categories = query(this, "category", () => ({
"filter[hasParent]": false,
Expand Down
4 changes: 2 additions & 2 deletions addon/components/document-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ export default class DocumentViewComponent extends Component {
@service notification;
@service store;
@service intl;
@service documents;
@service("alexandria-documents") documents;
@service router;
@service config;
@service("alexandria-config") config;

@tracked isDragOver = false;
@tracked dragCounter = 0;
Expand Down
2 changes: 1 addition & 1 deletion addon/components/documents-side-panel.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { inject as service } from "@ember/service";
import Component from "@glimmer/component";
export default class DocumentsSidePanelComponent extends Component {
@service sidePanel;
@service("alexandria-side-panel") sidePanel;
}
2 changes: 1 addition & 1 deletion addon/components/mark-manager.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { inject as service } from "@ember/service";
import Component from "@glimmer/component";
export default class TagManagerComponent extends Component {
@service marks;
@service("alexandria-marks") marks;

get documents() {
return this.args.documents.filter((document) => !document.isDeleted);
Expand Down
2 changes: 1 addition & 1 deletion addon/components/mark-manager/mark.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { inject as service } from "@ember/service";
import Component from "@glimmer/component";

export default class MarkManagerMarkComponent extends Component {
@service marks;
@service("alexandria-marks") marks;

get activeDocumentCount() {
return this.args.documents.reduce((acc, doc) => {
Expand Down
2 changes: 1 addition & 1 deletion addon/components/multi-document-details.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { inject as service } from "@ember/service";
import Component from "@glimmer/component";
export default class MultiDocumentDetailsComponent extends Component {
@service sidePanel;
@service("alexandria-side-panel") sidePanel;

get mergedTags() {
const tags = [];
Expand Down
2 changes: 1 addition & 1 deletion addon/components/side-panel-toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { inject as service } from "@ember/service";
import Component from "@glimmer/component";

export default class SidePanelToggleComponent extends Component {
@service sidePanel;
@service("alexandria-side-panel") sidePanel;
}
6 changes: 3 additions & 3 deletions addon/components/single-document-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import { ErrorHandler } from "ember-alexandria/helpers/error-handler";
// be inheriting from DocumentCard
export default class SingleDocumentDetailsComponent extends DocumentCard {
@service router;
@service documents;
@service tags;
@service sidePanel;
@service("alexandria-documents") documents;
@service("alexandria-tags") tags;
@service("alexandria-side-panel") sidePanel;
@service intl;

@tracked editTitle = false;
Expand Down
4 changes: 2 additions & 2 deletions addon/components/tag-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import Component from "@glimmer/component";
import { trackedFunction } from "ember-resources/util/function";
export default class TagFilterComponent extends Component {
@service router;
@service tags;
@service marks;
@service("alexandria-tags") tags;
@service("alexandria-marks") marks;
@service store;

get parsedSelected() {
Expand Down
2 changes: 1 addition & 1 deletion addon/components/tag-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { trackedFunction } from "ember-resources/util/function";

export default class TagManagerComponent extends Component {
@service("tags") tagService;
@service config;
@service("alexandria-config") config;
@service store;

@tracked tagValue;
Expand Down
2 changes: 1 addition & 1 deletion addon/controllers/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class ApplicationController extends Controller {
"sort",
];

@service config;
@service("alexandria-config") config;

@tracked category;
@tracked tags = [];
Expand Down
2 changes: 1 addition & 1 deletion addon/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class EmberAlexandriaEngine extends Engine {
Resolver = Resolver;

dependencies = {
services: ["session", "intl", "notification", "config"],
services: ["session", "intl", "notification", "alexandria-config"],
};
}

Expand Down
2 changes: 1 addition & 1 deletion addon/helpers/resolve-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Helper from "@ember/component/helper";
import { inject as service } from "@ember/service";

export default class ResolveGroupHelper extends Helper {
@service config;
@service("alexandria-config") config;

compute([id]) {
return this.config.resolveGroup(id);
Expand Down
2 changes: 1 addition & 1 deletion addon/helpers/resolve-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Helper from "@ember/component/helper";
import { inject as service } from "@ember/service";

export default class ResolveUserHelper extends Helper {
@service config;
@service("alexandria-config") config;

compute([id]) {
return this.config.resolveUser(id);
Expand Down
2 changes: 1 addition & 1 deletion addon/models/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class DocumentModel extends LocalizedModel {
@hasMany("mark", { inverse: "documents", async: true }) marks;
@hasMany("file", { inverse: "document", async: true }) files;

@service config;
@service("alexandria-config") config;

get thumbnail() {
const thumbnail = this.files.filter(
Expand Down
2 changes: 1 addition & 1 deletion addon/models/mark.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { attr, hasMany } from "@ember-data/model";
import { LocalizedModel, localizedAttr } from "ember-localized-model";

export default class MarkModel extends LocalizedModel {
@service config;
@service("alexandria-config") config;

@localizedAttr name;
@localizedAttr description;
Expand Down
6 changes: 3 additions & 3 deletions addon/routes/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export default class ApplicationRoute extends Route {
activeGroup: PARAM_OPTIONS,
};

@service config;
@service documents;
@service marks;
@service("alexandria-config") config;
@service("alexandria-documents") documents;
@service("alexandria-marks") marks;

model() {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Service from "@ember/service";
import { tracked } from "@glimmer/tracking";

export default class ConfigService extends Service {
export default class AlexandriaConfigService extends Service {
markIcons = {};

@tracked alexandriaQueryParams = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import Service, { inject as service } from "@ember/service";
import { tracked } from "@glimmer/tracking";
import fetch from "fetch";

export default class DocumentsService extends Service {
export default class AlexandriaDocumentsService extends Service {
@service store;
@service config;
@service("alexandria-config") config;
@service router;
@tracked selectedDocuments = [];
@tracked shortcutsDisabled = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { findAll } from "ember-data-resources";

import { ErrorHandler } from "ember-alexandria/helpers/error-handler";

export default class MarksService extends Service {
export default class AlexandriaMarksService extends Service {
@service store;

marks = findAll(this, "mark");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { action } from "@ember/object";
import Service from "@ember/service";
import { tracked } from "@glimmer/tracking";
export default class SidePanelService extends Service {

export default class AlexandriaSidePanelService extends Service {
@tracked open = true;

/**
Expand Down
4 changes: 2 additions & 2 deletions addon/services/tags.js → addon/services/alexandria-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { tracked } from "@glimmer/tracking";

import { ErrorHandler } from "ember-alexandria/helpers/error-handler";

export default class TagsService extends Service {
export default class AlexandriaTagsService extends Service {
@service store;
@service config;
@service("alexandria-config") config;

@tracked categoryCache;

Expand Down
7 changes: 1 addition & 6 deletions tests/dummy/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@ export default class App extends Application {
engines = {
"ember-alexandria": {
dependencies: {
services: [
"session",
"intl",
"notification",
{ config: "alexandria-config" },
],
services: ["session", "intl", "notification", "alexandria-config"],
},
},
};
Expand Down
11 changes: 8 additions & 3 deletions tests/dummy/app/services/alexandria-config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import ConfigService from "ember-alexandria/services/config";
import { later } from "@ember/runloop";
import { macroCondition, isTesting } from "@embroider/macros";

export default class AlexandriaConfigService extends ConfigService {
import AlexandriaConfigService from "ember-alexandria/services/alexandria-config";

export default class CustomAlexandriaConfigService extends AlexandriaConfigService {
markIcons = {
decision: "stamp",
};
Expand Down Expand Up @@ -28,8 +31,10 @@ export default class AlexandriaConfigService extends ConfigService {
}

resolveUser(id) {
const timeout = macroCondition(isTesting()) ? 1 : 200;

return new Promise((resolve) =>
setTimeout(() => resolve((id || "").toUpperCase()), 200),
later(this, () => resolve((id || "").toUpperCase()), timeout),
);
}
}
Loading
Loading