Refactored various modules for entities. Updated and refactored Kink scraper.
This commit is contained in:
@@ -100,6 +100,7 @@ function curateSite(site, network) {
|
||||
|
||||
function curateNetwork(network, releases) {
|
||||
const curatedNetwork = {
|
||||
...network,
|
||||
id: network.id,
|
||||
name: network.name,
|
||||
slug: network.slug,
|
||||
@@ -116,6 +117,19 @@ function curateNetwork(network, releases) {
|
||||
return curatedNetwork;
|
||||
}
|
||||
|
||||
function curateEntity(entity, parent, releases) {
|
||||
const curatedEntity = {
|
||||
...entity,
|
||||
children: [],
|
||||
};
|
||||
|
||||
if (entity.parent || parent) curatedEntity.parent = curateEntity(entity.parent || parent);
|
||||
if (entity.children) curatedEntity.children = entity.children.map(childEntity => curateEntity(childEntity, curatedEntity));
|
||||
if (releases) curatedEntity.releases = releases.map(release => curateRelease(release));
|
||||
|
||||
return curatedEntity;
|
||||
}
|
||||
|
||||
function curateTag(tag) {
|
||||
const curatedTag = {
|
||||
...tag,
|
||||
@@ -130,6 +144,7 @@ function curateTag(tag) {
|
||||
|
||||
export {
|
||||
curateActor,
|
||||
curateEntity,
|
||||
curateRelease,
|
||||
curateSite,
|
||||
curateNetwork,
|
||||
|
||||
179
assets/js/entities/actions.js
Normal file
179
assets/js/entities/actions.js
Normal file
@@ -0,0 +1,179 @@
|
||||
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
|
||||
children: childEntities(
|
||||
orderBy: [PRIORITY_DESC, NAME_ASC],
|
||||
) {
|
||||
id
|
||||
name
|
||||
slug
|
||||
url
|
||||
type
|
||||
priority
|
||||
}
|
||||
parent {
|
||||
id
|
||||
name
|
||||
slug
|
||||
type
|
||||
url
|
||||
}
|
||||
}
|
||||
connection: releasesConnection(
|
||||
first: $limit
|
||||
offset: $offset
|
||||
orderBy: $orderBy
|
||||
filter: {
|
||||
entity: {
|
||||
or: [
|
||||
{ parent: { slug: { equalTo: $entitySlug } } },
|
||||
{ parent: { parent: { slug: { equalTo: $entitySlug } } } }
|
||||
]
|
||||
}
|
||||
or: [
|
||||
{
|
||||
date: {
|
||||
lessThan: $before,
|
||||
greaterThan: $after
|
||||
}
|
||||
},
|
||||
{
|
||||
date: {
|
||||
isNull: true
|
||||
},
|
||||
createdAt: {
|
||||
lessThan: $beforeTime,
|
||||
greaterThan: $afterTime,
|
||||
}
|
||||
}
|
||||
]
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
||||
async function fetchEntities({ _commit }, { type }) {
|
||||
const { entities } = await graphql(`
|
||||
query Entities(
|
||||
$type: String! = "network"
|
||||
) {
|
||||
entities(
|
||||
orderBy: NAME_ASC
|
||||
filter: {
|
||||
type: {
|
||||
equalTo: $type
|
||||
}
|
||||
}
|
||||
) {
|
||||
id
|
||||
name
|
||||
slug
|
||||
type
|
||||
url
|
||||
}
|
||||
}
|
||||
`, { type });
|
||||
|
||||
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
|
||||
parent {
|
||||
name
|
||||
slug
|
||||
type
|
||||
url
|
||||
}
|
||||
}
|
||||
}
|
||||
`, {
|
||||
query,
|
||||
limit,
|
||||
});
|
||||
|
||||
return entities.map(entity => curateEntity(entity));
|
||||
}
|
||||
|
||||
return {
|
||||
fetchEntityBySlugAndType,
|
||||
fetchEntities,
|
||||
searchEntities,
|
||||
};
|
||||
}
|
||||
|
||||
export default initEntitiesActions;
|
||||
13
assets/js/entities/entities.js
Normal file
13
assets/js/entities/entities.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import state from './state';
|
||||
import mutations from './mutations';
|
||||
import actions from './actions';
|
||||
|
||||
function initEntitiesStore(store, router) {
|
||||
return {
|
||||
state,
|
||||
mutations,
|
||||
actions: actions(store, router),
|
||||
};
|
||||
}
|
||||
|
||||
export default initEntitiesStore;
|
||||
1
assets/js/entities/mutations.js
Normal file
1
assets/js/entities/mutations.js
Normal file
@@ -0,0 +1 @@
|
||||
export default {};
|
||||
1
assets/js/entities/state.js
Normal file
1
assets/js/entities/state.js
Normal file
@@ -0,0 +1 @@
|
||||
export default {};
|
||||
@@ -25,7 +25,7 @@ function initNetworksActions(store, _router) {
|
||||
$orderBy: [ReleasesOrderBy!]
|
||||
$exclude: [String!]
|
||||
) {
|
||||
network: entityBySlugAndType(slug: $networkSlug, type: 1) {
|
||||
network: entityBySlugAndType(slug: $networkSlug, type: "network") {
|
||||
id
|
||||
name
|
||||
slug
|
||||
@@ -37,12 +37,14 @@ function initNetworksActions(store, _router) {
|
||||
name
|
||||
slug
|
||||
url
|
||||
type
|
||||
priority
|
||||
}
|
||||
parent {
|
||||
id
|
||||
name
|
||||
slug
|
||||
type
|
||||
url
|
||||
}
|
||||
}
|
||||
@@ -51,10 +53,10 @@ function initNetworksActions(store, _router) {
|
||||
offset: $offset
|
||||
orderBy: $orderBy
|
||||
filter: {
|
||||
site: {
|
||||
entity: {
|
||||
or: [
|
||||
{ network: { slug: { equalTo: $networkSlug } } },
|
||||
{ network: { parent: { slug: { equalTo: $networkSlug } } } }
|
||||
{ parent: { slug: { equalTo: $networkSlug } } },
|
||||
{ parent: { parent: { slug: { equalTo: $networkSlug } } } }
|
||||
]
|
||||
}
|
||||
or: [
|
||||
@@ -116,13 +118,14 @@ function initNetworksActions(store, _router) {
|
||||
orderBy: NAME_ASC
|
||||
filter: {
|
||||
type: {
|
||||
equalTo: 1
|
||||
equalTo: "network"
|
||||
}
|
||||
}
|
||||
) {
|
||||
id
|
||||
name
|
||||
slug
|
||||
type
|
||||
url
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,18 +22,18 @@ function initSitesActions(store, _router) {
|
||||
$orderBy:[ReleasesOrderBy!]
|
||||
$exclude: [String!]
|
||||
) {
|
||||
site: siteBySlug(slug: $siteSlug) {
|
||||
site: entityBySlugAndType(slug: $siteSlug, type: 2) {
|
||||
name
|
||||
slug
|
||||
url
|
||||
tags: sitesTags {
|
||||
tags: entitiesTags {
|
||||
tag {
|
||||
id
|
||||
slug
|
||||
name
|
||||
}
|
||||
}
|
||||
network {
|
||||
network: parent {
|
||||
id
|
||||
name
|
||||
slug
|
||||
@@ -70,7 +70,7 @@ function initSitesActions(store, _router) {
|
||||
offset: $offset
|
||||
orderBy: $orderBy
|
||||
filter: {
|
||||
site: {
|
||||
entity: {
|
||||
slug: {
|
||||
equalTo: $siteSlug
|
||||
}
|
||||
@@ -122,7 +122,7 @@ function initSitesActions(store, _router) {
|
||||
$after:Date = "1900-01-01",
|
||||
$before:Date = "2100-01-01",
|
||||
) {
|
||||
site {
|
||||
site: entity {
|
||||
name
|
||||
slug
|
||||
url
|
||||
@@ -137,38 +137,9 @@ function initSitesActions(store, _router) {
|
||||
return sites;
|
||||
}
|
||||
|
||||
async function searchSites({ _commit }, { query, limit = 20 }) {
|
||||
const { sites } = await graphql(`
|
||||
query SearchSites(
|
||||
$query: String!
|
||||
$limit:Int = 20,
|
||||
) {
|
||||
sites: searchSites(
|
||||
search: $query,
|
||||
first: $limit
|
||||
) {
|
||||
name
|
||||
slug
|
||||
url
|
||||
network {
|
||||
name
|
||||
slug
|
||||
url
|
||||
}
|
||||
}
|
||||
}
|
||||
`, {
|
||||
query,
|
||||
limit,
|
||||
});
|
||||
|
||||
return sites;
|
||||
}
|
||||
|
||||
return {
|
||||
fetchSiteBySlug,
|
||||
fetchSites,
|
||||
searchSites,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import Vuex from 'vuex';
|
||||
import initUiStore from './ui/ui';
|
||||
import initAuthStore from './auth/auth';
|
||||
import initReleasesStore from './releases/releases';
|
||||
import initEntitiesStore from './entities/entities';
|
||||
import initSitesStore from './sites/sites';
|
||||
import initNetworksStore from './networks/networks';
|
||||
import initActorsStore from './actors/actors';
|
||||
@@ -18,6 +19,7 @@ function initStore(router) {
|
||||
store.registerModule('auth', initAuthStore(store, router));
|
||||
store.registerModule('releases', initReleasesStore(store, router));
|
||||
store.registerModule('actors', initActorsStore(store, router));
|
||||
store.registerModule('entities', initEntitiesStore(store, router));
|
||||
store.registerModule('sites', initSitesStore(store, router));
|
||||
store.registerModule('networks', initNetworksStore(store, router));
|
||||
store.registerModule('tags', initTagsStore(store, router));
|
||||
|
||||
Reference in New Issue
Block a user