forked from cardstack/boxel
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtrip-info.gts
113 lines (109 loc) · 3.24 KB
/
trip-info.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import StringField from 'https://cardstack.com/base/string';
import {
CardDef,
FieldDef,
contains,
field,
linksTo,
linksToMany,
} from 'https://cardstack.com/base/card-api';
import { Component } from 'https://cardstack.com/base/card-api';
import { CardContainer, FieldContainer } from '@cardstack/boxel-ui/components';
import { Country } from './country';
class TravelGoal extends FieldDef {
static displayName = 'Travel Goal';
@field goalTitle = contains(StringField);
@field country = linksTo(Country);
@field alternateTrips = linksToMany(Country);
static embedded = class Embedded extends Component<typeof this> {
<template>
<CardContainer class='container'>
<FieldContainer @label='Goal Title'>
<@fields.goalTitle />
</FieldContainer>
<FieldContainer @label='Country'>
<@fields.country />
</FieldContainer>
<FieldContainer @label='Alternate Trips'>
<@fields.alternateTrips />
</FieldContainer>
</CardContainer>
<style>
.container {
padding: 20px;
background-color: whitesmoke;
}
.container > * + * {
margin-top: 20px;
}
</style>
</template>
};
}
class Traveler extends FieldDef {
static displayName = 'Traveler';
@field name = contains(StringField);
@field countryOfOrigin = linksTo(Country);
@field countriesVisited = linksToMany(Country);
@field nextTravelGoal = contains(TravelGoal);
static embedded = class Embedded extends Component<typeof this> {
<template>
<div class='traveler'>
<FieldContainer @label='Name' @vertical={{true}}>
<@fields.name />
</FieldContainer>
<FieldContainer @label='Country of Origin' @vertical={{true}}>
{{#if @model.countryOfOrigin}}
<@fields.countryOfOrigin />
{{else}}
Unknown
{{/if}}
</FieldContainer>
<FieldContainer @label='Countries Visited' @vertical={{true}}>
{{#if @model.countriesVisited.length}}
<@fields.countriesVisited />
{{else}}
Unknown
{{/if}}
</FieldContainer>
<FieldContainer @label='Next Travel Goal' @vertical={{true}}>
<@fields.nextTravelGoal />
</FieldContainer>
</div>
<style>
.traveler {
display: grid;
gap: 20px;
}
</style>
</template>
};
}
export class TripInfo extends CardDef {
static displayName = 'Trip Info';
@field destinations = linksToMany(Country);
@field traveler = contains(Traveler);
@field title = contains(StringField, {
computeVia: function (this: TripInfo) {
return this.traveler?.name
? `Trip Info for ${this.traveler.name}`
: 'Trip Info';
},
});
@field startLocation = linksTo(Country);
@field endLocation = linksTo(Country);
/*
static isolated = class Isolated extends Component<typeof this> {
<template></template>
}
static embedded = class Embedded extends Component<typeof this> {
<template></template>
}
static atom = class Atom extends Component<typeof this> {
<template></template>
}
static edit = class Edit extends Component<typeof this> {
<template></template>
}
*/
}