Replaced default height and weight fields with fields taking units argument.

This commit is contained in:
ThePendulum 2019-12-16 02:39:13 +01:00
parent 577c03f9b7
commit f4c2e6c08c
8 changed files with 133 additions and 26 deletions

View File

@ -136,8 +136,8 @@
>
<dfn class="bio-label"><Icon icon="height" />Height</dfn>
<span>
<span class="height-metric">{{ actor.height }} cm</span>
<span class="height-imperial">{{ imperialHeight.feet }}' {{ imperialHeight.inches }}"</span>
<span class="height-metric">{{ actor.height.metric }} cm</span>
<span class="height-imperial">{{ actor.height.imperial }}</span>
</span>
</li>
@ -148,8 +148,8 @@
<dfn class="bio-label"><Icon icon="scale" />Weight</dfn>
<span>
<span class="weight-metric">{{ actor.weight }} kg</span>
<span class="weight-imperial">{{ imperialWeight }} lbs</span>
<span class="weight-metric">{{ actor.weight.metric }} kg</span>
<span class="weight-imperial">{{ actor.weight.imperial }} lbs</span>
</span>
</li>
@ -239,8 +239,6 @@
</template>
<script>
import { cmToFeetInches, kgToLbs } from '../../../src/utils/convert';
import Photos from './photos.vue';
import FilterBar from '../header/filter-bar.vue';
import Releases from '../releases/releases.vue';
@ -249,14 +247,6 @@ async function fetchReleases() {
this.releases = await this.$store.dispatch('fetchActorReleases', this.$route.params.actorSlug);
}
function imperialHeight() {
return cmToFeetInches(this.actor.height);
}
function imperialWeight() {
return kgToLbs(this.actor.weight);
}
function scrollPhotos(event) {
event.currentTarget.scrollLeft += event.deltaY; // eslint-disable-line no-param-reassign
}
@ -286,10 +276,6 @@ export default {
expanded: false,
};
},
computed: {
imperialHeight,
imperialWeight,
},
mounted,
methods: {
fetchReleases,

View File

@ -4,8 +4,23 @@ function curateActor(actor) {
const curatedActor = {
...actor,
avatar: actor.avatar[0],
origin: {
country: actor.originCountry,
height: actor.heightMetric && {
metric: actor.heightMetric,
imperial: actor.heightImperial,
},
weight: actor.weightMetric && {
metric: actor.weightMetric,
imperial: actor.weightImperial,
},
origin: actor.birthCountry && {
city: actor.birthCity,
state: actor.birthState,
country: actor.birthCountry,
},
residence: actor.residenceCountry && {
city: actor.residenceCity,
state: actor.residenceState,
country: actor.residenceCountry,
},
};
@ -20,14 +35,50 @@ function initActorActions(store, _router) {
id
name
slug
gender
birthdate
age
ethnicity
bust
waist
hip
heightMetric: height(units:METRIC)
heightImperial: height(units:IMPERIAL)
weightMetric: weight(units:METRIC)
weightImperial: weight(units:IMPERIAL)
hasTattoos
hasPiercings
tattoos
piercings
avatar: actorsMediasByTargetId(condition: { role:"avatar" }) {
thumbnail
path
}
originCountry: countryByBirthCountryAlpha2 {
photos: actorsMediasByTargetId(condition: { role:"photo" }) {
id
thumbnail
path
index
}
birthCity
birthState
birthCountry: countryByBirthCountryAlpha2 {
alpha2
name
alias
}
residenceCity
residenceState
residenceCountry: countryByResidenceCountryAlpha2 {
alpha2
name
alias
}
social: actorsSocialsByTargetId {
id
url
platform
}
aliases: actorsByAliasFor {
id
name
@ -56,7 +107,7 @@ function initActorActions(store, _router) {
avatar: actorsMediasByTargetId(condition: { role:"avatar" }) {
thumbnail
}
originCountry: countryByBirthCountryAlpha2 {
birthCountry: countryByBirthCountryAlpha2 {
alpha2
name
alias
@ -67,8 +118,6 @@ function initActorActions(store, _router) {
limit,
});
console.log(actors);
return actors.map(actor => curateActor(actor));
}

View File

@ -47,6 +47,7 @@ function initReleasesActions(_store, _router) {
name
slug
birthdate
age
originCountry: countryByBirthCountryAlpha2 {
alpha2
name
@ -111,6 +112,7 @@ function initReleasesActions(_store, _router) {
name
slug
birthdate
age
originCountry: countryByBirthCountryAlpha2 {
alpha2
name

View File

@ -296,11 +296,18 @@ exports.up = knex => Promise.resolve()
CREATE VIEW releases_tags AS SELECT * FROM tags_associated WHERE domain = 'releases';
CREATE VIEW actors_social AS SELECT * FROM social WHERE domain = 'actors';
COMMENT ON VIEW releases_media IS E'@foreignKey (target_id) references releases (id)|@fieldName releaseMedia';
COMMENT ON VIEW actors_media IS E'@foreignKey (target_id) references actors (id)|@fieldName actorMedia';
COMMENT ON VIEW tags_media IS E'@foreignKey (target_id) references tags (id)|@fieldName tagMedia';
COMMENT ON VIEW releases_tags IS E'@foreignKey (target_id) references releases (id)\n@foreignKey (tag_id) references tags (id)|@fieldName releaseTag';
COMMENT ON VIEW actors_social IS E'@foreignKey (target_id) references actors (id)|@fieldName actorSocial';
COMMENT ON VIEW releases_tags IS E'@foreignKey (target_id) references releases (id)|@fieldName tagRelease\n@foreignKey (tag_id) references tags (id)|@fieldName releaseTag';
COMMENT ON COLUMN actors.height IS E'@omit read,update,create,delete,all,many';
COMMENT ON COLUMN actors.weight IS E'@omit read,update,create,delete,all,many';
`));
exports.down = knex => Promise.resolve()
@ -310,6 +317,8 @@ exports.down = knex => Promise.resolve()
DROP VIEW tags_media;
DROP VIEW releases_tags;
DROP VIEW actors_social;
`))
.then(() => knex.schema.dropTable('tags_associated'))
.then(() => knex.schema.dropTable('directors_associated'))

View File

@ -83,6 +83,7 @@
"express-react-views": "^0.11.0",
"face-api.js": "^0.21.0",
"fs-extra": "^7.0.1",
"graphile-utils": "^4.5.6",
"jsdom": "^15.2.1",
"knex": "^0.16.5",
"knex-migrate": "^1.7.4",

48
src/web/plugins/actors.js Normal file
View File

@ -0,0 +1,48 @@
'use strict';
const { makeExtendSchemaPlugin, gql } = require('graphile-utils');
const moment = require('moment');
const { cmToFeetInches, kgToLbs } = require('../../utils/convert');
const schemaExtender = makeExtendSchemaPlugin(_build => ({
typeDefs: gql`
enum Units {
METRIC
IMPERIAL
}
extend type Actor {
age: Int @requires(columns: ["birthdate"])
height(units:Units): String @requires(columns: ["height"])
weight(units:Units): String @requires(columns: ["weight"])
}
`,
resolvers: {
Actor: {
age(parent, _args, _context, _info) {
if (!parent.birthdate) return null;
return moment().diff(parent.birthdate, 'years');
},
height(parent, args, _context, _info) {
if (!parent.height) return null;
if (args.units === 'IMPERIAL') {
const { feet, inches } = cmToFeetInches(parent.height);
return `${feet}' ${inches}"`;
}
return parent.height.toString();
},
weight(parent, args, _context, _info) {
if (!parent.weight) return null;
return args.units === 'IMPERIAL'
? kgToLbs(parent.weight).toString()
: parent.weight.toString();
},
},
},
}));
module.exports = [schemaExtender];

View File

@ -0,0 +1,7 @@
'use strict';
const ActorPlugins = require('./actors');
module.exports = {
ActorPlugins,
};

View File

@ -10,6 +10,8 @@ const bodyParser = require('body-parser');
const ConnectionFilterPlugin = require('postgraphile-plugin-connection-filter');
const PgSimplifyInflectorPlugin = require('@graphile-contrib/pg-simplify-inflector');
const { ActorPlugins } = require('./plugins/plugins');
const {
fetchReleases,
fetchReleaseById,
@ -47,7 +49,10 @@ function initServer() {
graphileBuildOptions: {
pgOmitListSuffix: true,
},
appendPlugins: [PgSimplifyInflectorPlugin, ConnectionFilterPlugin],
appendPlugins: [
PgSimplifyInflectorPlugin, ConnectionFilterPlugin,
...ActorPlugins,
],
},
));