forked from cardstack/boxel
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpickup-games-scheduler.gts
69 lines (66 loc) · 1.98 KB
/
pickup-games-scheduler.gts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import {
contains,
containsMany,
field,
linksToMany,
CardDef,
} from 'https://cardstack.com/base/card-api';
import { Component } from 'https://cardstack.com/base/card-api';
import StringField from 'https://cardstack.com/base/string';
import NumberField from 'https://cardstack.com/base/number';
import DateTimeField from 'https://cardstack.com/base/datetime';
import { format as formatDate } from 'date-fns';
export class GameSlot extends CardDef {
static displayName = 'Game Slot';
@field location = contains(StringField);
@field minPlayers = contains(NumberField);
@field maxPlayers = contains(NumberField);
@field startTime = contains(DateTimeField);
@field endTime = contains(DateTimeField);
@field players = containsMany(StringField);
@field title = contains(StringField, {
computeVia(this: GameSlot) {
if (this.startTime) {
let result = formatDate(this.startTime, 'iiii M/d h:mm aa');
if (this.location) {
result = result + ` (${this.location})`;
}
return result;
}
return 'Untitled';
},
});
static embedded = class Embedded extends Component<typeof this> {
get playerCount() {
return this.args.model.players?.length ?? 0;
}
get hasEnoughPlayers() {
return this.playerCount >= (this.args.model.minPlayers || 1);
}
<template>
<div class={{if this.hasEnoughPlayers 'game-on' 'need-more'}}>
<h3><@fields.title /></h3>
<ul>
{{#unless @fields.players.length}}
<li><em>Nobody yet</em></li>
{{/unless}}
{{#each @fields.players as |player|}}
<li><player /></li>
{{/each}}
</ul>
</div>
<style>
h3 {
margin-top: 0;
}
.game-on {
background-color: #d1ffbd;
}
</style>
</template>
};
}
export class PickupGamesScheduler extends CardDef {
static displayName = 'Pickup Games Scheduler';
@field gameSlots = linksToMany(GameSlot);
}