2020-06-27 00:57:30 +00:00
|
|
|
import { graphql } from '../api';
|
|
|
|
// import { sitesFragment, releaseFields } from '../fragments';
|
|
|
|
import { releaseFields } from '../fragments';
|
|
|
|
import { curateEntity } from '../curate';
|
|
|
|
import getDateRange from '../get-date-range';
|
|
|
|
|
|
|
|
function initEntitiesActions(store, _router) {
|
|
|
|
async function fetchEntityBySlugAndType({ _commit }, {
|
|
|
|
entitySlug,
|
|
|
|
entityType,
|
|
|
|
limit = 10,
|
|
|
|
pageNumber = 1,
|
|
|
|
range = 'latest',
|
|
|
|
}) {
|
|
|
|
const { before, after, orderBy } = getDateRange(range);
|
|
|
|
|
|
|
|
const { entity, connection: { releases, totalCount } } = await graphql(`
|
|
|
|
query Entity(
|
|
|
|
$entitySlug: String!
|
|
|
|
$entityType: String! = "channel"
|
|
|
|
$limit: Int = 10,
|
|
|
|
$offset: Int = 0,
|
|
|
|
$after: Date = "1900-01-01",
|
|
|
|
$before: Date = "2100-01-01",
|
|
|
|
$afterTime: Datetime = "1900-01-01",
|
|
|
|
$beforeTime: Datetime = "2100-01-01",
|
|
|
|
$orderBy: [ReleasesOrderBy!]
|
|
|
|
$exclude: [String!]
|
|
|
|
) {
|
|
|
|
entity: entityBySlugAndType(slug: $entitySlug, type: $entityType) {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
url
|
2020-07-02 02:04:28 +00:00
|
|
|
independent
|
2020-06-27 22:44:53 +00:00
|
|
|
hasLogo
|
2020-07-05 02:10:35 +00:00
|
|
|
tags: entitiesTags {
|
|
|
|
tag {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
}
|
|
|
|
}
|
2020-06-28 01:58:16 +00:00
|
|
|
children: childEntitiesConnection(
|
2020-06-27 00:57:30 +00:00
|
|
|
orderBy: [PRIORITY_DESC, NAME_ASC],
|
2020-07-02 23:28:22 +00:00
|
|
|
filter: {
|
|
|
|
type: {
|
|
|
|
notEqualTo: "info"
|
|
|
|
}
|
2020-07-08 00:53:46 +00:00
|
|
|
visible: {
|
|
|
|
equalTo: true
|
|
|
|
}
|
2020-07-02 23:28:22 +00:00
|
|
|
}
|
2020-06-27 00:57:30 +00:00
|
|
|
) {
|
2020-06-28 01:58:16 +00:00
|
|
|
nodes {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
url
|
|
|
|
type
|
|
|
|
priority
|
2020-07-02 23:28:22 +00:00
|
|
|
independent
|
2020-06-28 01:58:16 +00:00
|
|
|
hasLogo
|
|
|
|
}
|
2020-06-27 00:57:30 +00:00
|
|
|
}
|
|
|
|
parent {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
type
|
|
|
|
url
|
2020-07-02 02:04:28 +00:00
|
|
|
independent
|
2020-06-27 22:44:53 +00:00
|
|
|
hasLogo
|
2020-06-27 00:57:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
connection: releasesConnection(
|
|
|
|
first: $limit
|
|
|
|
offset: $offset
|
|
|
|
orderBy: $orderBy
|
|
|
|
filter: {
|
2020-06-30 22:25:27 +00:00
|
|
|
and: [
|
2020-06-27 00:57:30 +00:00
|
|
|
{
|
2020-06-30 22:25:27 +00:00
|
|
|
or: [
|
|
|
|
{
|
|
|
|
entity: {
|
|
|
|
or: [
|
|
|
|
{ slug: { equalTo: $entitySlug } },
|
|
|
|
{ parent: { slug: { equalTo: $entitySlug } } },
|
|
|
|
{ parent: { parent: { slug: { equalTo: $entitySlug } } } }
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
studio: {
|
|
|
|
slug: { equalTo: $entitySlug },
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2020-06-27 00:57:30 +00:00
|
|
|
{
|
2020-06-30 22:25:27 +00:00
|
|
|
or: [
|
|
|
|
{
|
|
|
|
date: {
|
|
|
|
lessThan: $before,
|
|
|
|
greaterThan: $after
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
date: {
|
|
|
|
isNull: true
|
|
|
|
},
|
|
|
|
createdAt: {
|
|
|
|
lessThan: $beforeTime,
|
|
|
|
greaterThan: $afterTime,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
2020-06-27 00:57:30 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
releasesTagsConnection: {
|
|
|
|
none: {
|
|
|
|
tag: {
|
|
|
|
slug: {
|
|
|
|
in: $exclude
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
) {
|
|
|
|
releases: nodes {
|
|
|
|
${releaseFields}
|
|
|
|
}
|
|
|
|
totalCount
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, {
|
|
|
|
entitySlug,
|
|
|
|
entityType,
|
|
|
|
limit,
|
|
|
|
offset: Math.max(0, (pageNumber - 1)) * limit,
|
|
|
|
after,
|
|
|
|
before,
|
|
|
|
orderBy,
|
|
|
|
afterTime: store.getters.after,
|
|
|
|
beforeTime: store.getters.before,
|
|
|
|
exclude: store.state.ui.filter,
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
entity: curateEntity(entity, null, releases),
|
|
|
|
totalCount,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-06-27 22:15:13 +00:00
|
|
|
async function fetchEntities({ _commit }, { type, entitySlugs }) {
|
2020-06-27 00:57:30 +00:00
|
|
|
const { entities } = await graphql(`
|
|
|
|
query Entities(
|
2020-06-27 22:15:13 +00:00
|
|
|
$entitySlugs: [String!] = []
|
2020-06-27 00:57:30 +00:00
|
|
|
) {
|
|
|
|
entities(
|
|
|
|
orderBy: NAME_ASC
|
|
|
|
filter: {
|
2020-06-27 22:15:13 +00:00
|
|
|
or: [
|
|
|
|
{
|
|
|
|
type: {
|
2020-07-02 02:04:28 +00:00
|
|
|
equalTo: "network"
|
2020-06-27 22:15:13 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-02 02:04:28 +00:00
|
|
|
{
|
|
|
|
independent: {
|
|
|
|
equalTo: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
type: {
|
|
|
|
equalTo: "channel"
|
|
|
|
}
|
|
|
|
parentExists: false
|
|
|
|
}
|
2020-06-27 22:15:13 +00:00
|
|
|
{
|
|
|
|
slug: {
|
|
|
|
in: $entitySlugs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
2020-06-27 00:57:30 +00:00
|
|
|
}
|
|
|
|
) {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
type
|
|
|
|
url
|
2020-07-02 23:28:22 +00:00
|
|
|
independent
|
2020-06-27 22:44:53 +00:00
|
|
|
hasLogo
|
2020-06-28 01:58:16 +00:00
|
|
|
children: childEntitiesConnection {
|
|
|
|
totalCount
|
|
|
|
}
|
2020-06-27 00:57:30 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-27 22:15:13 +00:00
|
|
|
`, {
|
|
|
|
type,
|
|
|
|
entitySlugs,
|
|
|
|
});
|
2020-06-27 00:57:30 +00:00
|
|
|
|
|
|
|
return entities.map(entity => curateEntity(entity));
|
|
|
|
}
|
|
|
|
|
|
|
|
async function searchEntities({ _commit }, { query, limit = 20 }) {
|
|
|
|
const { entities } = await graphql(`
|
|
|
|
query SearchEntities(
|
|
|
|
$query: String!
|
|
|
|
$limit:Int = 20,
|
|
|
|
) {
|
|
|
|
entities: searchEntities(
|
|
|
|
search: $query,
|
|
|
|
first: $limit
|
|
|
|
) {
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
type
|
|
|
|
url
|
2020-07-02 23:28:22 +00:00
|
|
|
independent
|
2020-06-27 22:44:53 +00:00
|
|
|
hasLogo
|
2020-06-27 00:57:30 +00:00
|
|
|
parent {
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
type
|
|
|
|
url
|
2020-06-27 22:44:53 +00:00
|
|
|
hasLogo
|
2020-06-27 00:57:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, {
|
|
|
|
query,
|
|
|
|
limit,
|
|
|
|
});
|
|
|
|
|
|
|
|
return entities.map(entity => curateEntity(entity));
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
fetchEntityBySlugAndType,
|
|
|
|
fetchEntities,
|
|
|
|
searchEntities,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default initEntitiesActions;
|