Initial version.
@@ -0,0 +1,4 @@
|
||||
dist/
|
||||
.idea/
|
||||
elm-stuff/
|
||||
node_modules/
|
||||
@@ -0,0 +1,3 @@
|
||||
[submodule "client/elm-material"]
|
||||
path = client/elm-material
|
||||
url = https://github.com/Lattyware/elm-material.git
|
||||
@@ -0,0 +1,661 @@
|
||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
@@ -0,0 +1,43 @@
|
||||
# [Many Decks][hosted]
|
||||
|
||||
[](https://github.com/Lattyware/manydecks/actions)
|
||||
[](LICENSE)
|
||||
|
||||
Many Decks is a free, open source deck source that can be used to host decks for [Massive Decks][md], a comedy party game based on
|
||||
Cards against Humanity.
|
||||
|
||||
Please note this is a very early version and there will be rough edges, please do report bugs!
|
||||
|
||||
**[Many Decks][hosted]**
|
||||
|
||||
[hosted]: https://decks.md.rereadgames.com
|
||||
[md]: https://github.com/Lattyware/massivedecks
|
||||
|
||||
## About
|
||||
|
||||
Many Decks is open source software available under [the AGPLv3 license](LICENSE) and written in [Elm][elm] and
|
||||
[TypeScript][typescript].
|
||||
|
||||
[elm]: https://elm-lang.org/
|
||||
[typescript]: https://www.typescriptlang.org/
|
||||
|
||||
## Use
|
||||
|
||||
To use, [the hosted version][hosted] is easiest.
|
||||
|
||||
|
||||
|
||||
## Contributing
|
||||
|
||||
If you have any problems with the editor, please [raise an issue][issue]. If you would like to help develop it, pull
|
||||
requests are welcome.
|
||||
|
||||
[issue]: https://github.com/Lattyware/massivedecks/issues/new
|
||||
|
||||
## Credits
|
||||
|
||||
### Maintainers
|
||||
|
||||
Many Decks is maintained by [Reread Games][reread].
|
||||
|
||||
[reread]: https://www.rereadgames.com/
|
||||
@@ -0,0 +1,39 @@
|
||||
FROM node:14-alpine
|
||||
|
||||
ARG VERSION=dev
|
||||
ENV MD_VERSION $VERSION
|
||||
|
||||
WORKDIR /md
|
||||
|
||||
COPY ["./package.json", "./package-lock.json", "./"]
|
||||
# COPY ["./elm-material/package.json", "./elm-material/package-lock.json", "./elm-material/"]
|
||||
|
||||
RUN ["apk", "add", "--no-cache", "--virtual", ".gyp", "python", "make", "g++"]
|
||||
RUN ["npm", "ci"]
|
||||
|
||||
COPY ["./tsconfig.json", "./webpack.config.js", "./elm.json", "./"]
|
||||
COPY ["./src", "./src"]
|
||||
COPY ["./elm-material/src", "./elm-material/src"]
|
||||
COPY ["./assets", "./assets"]
|
||||
RUN ["npm", "run", "build"]
|
||||
|
||||
FROM nginx:mainline-alpine
|
||||
|
||||
ARG BUILD_DATE
|
||||
ARG VCS_REF
|
||||
ARG VERSION=dev
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
LABEL org.label-schema.name="manydecks/client"
|
||||
LABEL org.label-schema.description="The web client for Many Decks, a deck source for Massive Decks."
|
||||
LABEL org.label-schema.url="https://github.com/Lattyware/manydecks"
|
||||
LABEL org.label-schema.vcs-url="https://github.com/Lattyware/manydecks"
|
||||
LABEL org.label-schema.vendor="Reread Games"
|
||||
LABEL org.label-schema.schema-version="1.0"
|
||||
LABEL org.label-schema.build-date=$BUILD_DATE
|
||||
LABEL org.label-schema.vcs-ref=$VCS_REF
|
||||
LABEL org.label-schema.version=$VERSION
|
||||
|
||||
COPY --from=0 ["/md/dist", "/usr/share/nginx/html/"]
|
||||
COPY ["./nginx.conf", "/etc/nginx/nginx.conf"]
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="512" height="376">
|
||||
<path stroke="#fff" stroke-width="8" d="M10 89l246-79 80 246-247 80z"/>
|
||||
<path fill="#fff" stroke="#000" stroke-width="8" d="M146 63h239v238H146z"/>
|
||||
<path fill="#fff" stroke="#000" stroke-width="8" d="M279 63l223 76-72 227-227-76z"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 367 B |
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg width="46px" height="46px" viewBox="0 0 46 46" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sketch="http://www.bohemiancoding.com/sketch/ns">
|
||||
<!-- Generator: Sketch 3.3.3 (12081) - http://www.bohemiancoding.com/sketch -->
|
||||
<title>btn_google_dark_disabled_ios</title>
|
||||
<desc>Created with Sketch.</desc>
|
||||
<defs>
|
||||
<rect id="path-1" x="0" y="0" width="40" height="40" rx="2"></rect>
|
||||
</defs>
|
||||
<g id="Google-Button" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage">
|
||||
<g id="9-PATCH" sketch:type="MSArtboardGroup" transform="translate(-788.000000, -219.000000)"></g>
|
||||
<g id="btn_google_dark_disabled" sketch:type="MSArtboardGroup" transform="translate(-1.000000, -1.000000)">
|
||||
<g id="button" sketch:type="MSLayerGroup" transform="translate(4.000000, 4.000000)">
|
||||
<g id="button-bg">
|
||||
<use fill-opacity="0.08" fill="#000000" fill-rule="evenodd" sketch:type="MSShapeGroup" xlink:href="#path-1"></use>
|
||||
<use fill="none" xlink:href="#path-1"></use>
|
||||
<use fill="none" xlink:href="#path-1"></use>
|
||||
<use fill="none" xlink:href="#path-1"></use>
|
||||
</g>
|
||||
</g>
|
||||
<path d="M24.001,25.71 L24.001,22.362 L32.425,22.362 C32.551,22.929 32.65,23.46 32.65,24.207 C32.65,29.346 29.203,33 24.01,33 C19.042,33 15.01,28.968 15.01,24 C15.01,19.032 19.042,15 24.01,15 C26.44,15 28.474,15.891 30.031,17.349 L27.475,19.833 C26.827,19.221 25.693,18.501 24.01,18.501 C21.031,18.501 18.601,20.976 18.601,24.009 C18.601,27.042 21.031,29.517 24.01,29.517 C27.457,29.517 28.726,27.132 28.96,25.719 L24.001,25.719 L24.001,25.71 Z" id="Shape-Copy" fill-opacity="0.4" fill="#000000" sketch:type="MSShapeGroup"></path>
|
||||
<g id="handles_square" sketch:type="MSLayerGroup"></g>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.9 KiB |
@@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg width="46px" height="46px" viewBox="0 0 46 46" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sketch="http://www.bohemiancoding.com/sketch/ns">
|
||||
<!-- Generator: Sketch 3.3.3 (12081) - http://www.bohemiancoding.com/sketch -->
|
||||
<title>btn_google_dark_focus_ios</title>
|
||||
<desc>Created with Sketch.</desc>
|
||||
<defs>
|
||||
<filter x="-50%" y="-50%" width="200%" height="200%" filterUnits="objectBoundingBox" id="filter-1">
|
||||
<feOffset dx="0" dy="1" in="SourceAlpha" result="shadowOffsetOuter1"></feOffset>
|
||||
<feGaussianBlur stdDeviation="0.5" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
|
||||
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.168 0" in="shadowBlurOuter1" type="matrix" result="shadowMatrixOuter1"></feColorMatrix>
|
||||
<feOffset dx="0" dy="0" in="SourceAlpha" result="shadowOffsetOuter2"></feOffset>
|
||||
<feGaussianBlur stdDeviation="0.5" in="shadowOffsetOuter2" result="shadowBlurOuter2"></feGaussianBlur>
|
||||
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.084 0" in="shadowBlurOuter2" type="matrix" result="shadowMatrixOuter2"></feColorMatrix>
|
||||
<feMerge>
|
||||
<feMergeNode in="shadowMatrixOuter1"></feMergeNode>
|
||||
<feMergeNode in="shadowMatrixOuter2"></feMergeNode>
|
||||
<feMergeNode in="SourceGraphic"></feMergeNode>
|
||||
</feMerge>
|
||||
</filter>
|
||||
<rect id="path-2" x="0" y="0" width="40" height="40" rx="2"></rect>
|
||||
<rect id="path-3" x="5" y="5" width="38" height="38" rx="1"></rect>
|
||||
</defs>
|
||||
<g id="Google-Button" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage">
|
||||
<g id="9-PATCH" sketch:type="MSArtboardGroup" transform="translate(-668.000000, -219.000000)"></g>
|
||||
<g id="btn_google_dark_focus" sketch:type="MSArtboardGroup" transform="translate(-1.000000, -1.000000)">
|
||||
<rect id="Rectangle-14" fill-opacity="0.3" fill="#4285F4" sketch:type="MSShapeGroup" x="1" y="1" width="46" height="46"></rect>
|
||||
<g id="button" sketch:type="MSLayerGroup" transform="translate(4.000000, 4.000000)" filter="url(#filter-1)">
|
||||
<g id="button-bg">
|
||||
<use fill="#4285F4" fill-rule="evenodd" sketch:type="MSShapeGroup" xlink:href="#path-2"></use>
|
||||
<use fill="none" xlink:href="#path-2"></use>
|
||||
<use fill="none" xlink:href="#path-2"></use>
|
||||
<use fill="none" xlink:href="#path-2"></use>
|
||||
</g>
|
||||
</g>
|
||||
<g id="button-bg-copy">
|
||||
<use fill="#FFFFFF" fill-rule="evenodd" sketch:type="MSShapeGroup" xlink:href="#path-3"></use>
|
||||
<use fill="none" xlink:href="#path-3"></use>
|
||||
<use fill="none" xlink:href="#path-3"></use>
|
||||
<use fill="none" xlink:href="#path-3"></use>
|
||||
</g>
|
||||
<g id="logo_googleg_48dp" sketch:type="MSLayerGroup" transform="translate(15.000000, 15.000000)">
|
||||
<path d="M17.64,9.20454545 C17.64,8.56636364 17.5827273,7.95272727 17.4763636,7.36363636 L9,7.36363636 L9,10.845 L13.8436364,10.845 C13.635,11.97 13.0009091,12.9231818 12.0477273,13.5613636 L12.0477273,15.8195455 L14.9563636,15.8195455 C16.6581818,14.2527273 17.64,11.9454545 17.64,9.20454545 L17.64,9.20454545 Z" id="Shape" fill="#4285F4" sketch:type="MSShapeGroup"></path>
|
||||
<path d="M9,18 C11.43,18 13.4672727,17.1940909 14.9563636,15.8195455 L12.0477273,13.5613636 C11.2418182,14.1013636 10.2109091,14.4204545 9,14.4204545 C6.65590909,14.4204545 4.67181818,12.8372727 3.96409091,10.71 L0.957272727,10.71 L0.957272727,13.0418182 C2.43818182,15.9831818 5.48181818,18 9,18 L9,18 Z" id="Shape" fill="#34A853" sketch:type="MSShapeGroup"></path>
|
||||
<path d="M3.96409091,10.71 C3.78409091,10.17 3.68181818,9.59318182 3.68181818,9 C3.68181818,8.40681818 3.78409091,7.83 3.96409091,7.29 L3.96409091,4.95818182 L0.957272727,4.95818182 C0.347727273,6.17318182 0,7.54772727 0,9 C0,10.4522727 0.347727273,11.8268182 0.957272727,13.0418182 L3.96409091,10.71 L3.96409091,10.71 Z" id="Shape" fill="#FBBC05" sketch:type="MSShapeGroup"></path>
|
||||
<path d="M9,3.57954545 C10.3213636,3.57954545 11.5077273,4.03363636 12.4404545,4.92545455 L15.0218182,2.34409091 C13.4631818,0.891818182 11.4259091,0 9,0 C5.48181818,0 2.43818182,2.01681818 0.957272727,4.95818182 L3.96409091,7.29 C4.67181818,5.16272727 6.65590909,3.57954545 9,3.57954545 L9,3.57954545 Z" id="Shape" fill="#EA4335" sketch:type="MSShapeGroup"></path>
|
||||
<path d="M0,0 L18,0 L18,18 L0,18 L0,0 Z" id="Shape" sketch:type="MSShapeGroup"></path>
|
||||
</g>
|
||||
<g id="handles_square" sketch:type="MSLayerGroup"></g>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 4.8 KiB |
@@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg width="46px" height="46px" viewBox="0 0 46 46" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sketch="http://www.bohemiancoding.com/sketch/ns">
|
||||
<!-- Generator: Sketch 3.3.3 (12081) - http://www.bohemiancoding.com/sketch -->
|
||||
<title>btn_google_dark_normal_ios</title>
|
||||
<desc>Created with Sketch.</desc>
|
||||
<defs>
|
||||
<filter x="-50%" y="-50%" width="200%" height="200%" filterUnits="objectBoundingBox" id="filter-1">
|
||||
<feOffset dx="0" dy="1" in="SourceAlpha" result="shadowOffsetOuter1"></feOffset>
|
||||
<feGaussianBlur stdDeviation="0.5" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
|
||||
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.168 0" in="shadowBlurOuter1" type="matrix" result="shadowMatrixOuter1"></feColorMatrix>
|
||||
<feOffset dx="0" dy="0" in="SourceAlpha" result="shadowOffsetOuter2"></feOffset>
|
||||
<feGaussianBlur stdDeviation="0.5" in="shadowOffsetOuter2" result="shadowBlurOuter2"></feGaussianBlur>
|
||||
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.084 0" in="shadowBlurOuter2" type="matrix" result="shadowMatrixOuter2"></feColorMatrix>
|
||||
<feMerge>
|
||||
<feMergeNode in="shadowMatrixOuter1"></feMergeNode>
|
||||
<feMergeNode in="shadowMatrixOuter2"></feMergeNode>
|
||||
<feMergeNode in="SourceGraphic"></feMergeNode>
|
||||
</feMerge>
|
||||
</filter>
|
||||
<rect id="path-2" x="0" y="0" width="40" height="40" rx="2"></rect>
|
||||
<rect id="path-3" x="5" y="5" width="38" height="38" rx="1"></rect>
|
||||
</defs>
|
||||
<g id="Google-Button" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage">
|
||||
<g id="9-PATCH" sketch:type="MSArtboardGroup" transform="translate(-608.000000, -219.000000)"></g>
|
||||
<g id="btn_google_dark_normal" sketch:type="MSArtboardGroup" transform="translate(-1.000000, -1.000000)">
|
||||
<g id="button" sketch:type="MSLayerGroup" transform="translate(4.000000, 4.000000)" filter="url(#filter-1)">
|
||||
<g id="button-bg">
|
||||
<use fill="#4285F4" fill-rule="evenodd" sketch:type="MSShapeGroup" xlink:href="#path-2"></use>
|
||||
<use fill="none" xlink:href="#path-2"></use>
|
||||
<use fill="none" xlink:href="#path-2"></use>
|
||||
<use fill="none" xlink:href="#path-2"></use>
|
||||
</g>
|
||||
</g>
|
||||
<g id="button-bg-copy">
|
||||
<use fill="#FFFFFF" fill-rule="evenodd" sketch:type="MSShapeGroup" xlink:href="#path-3"></use>
|
||||
<use fill="none" xlink:href="#path-3"></use>
|
||||
<use fill="none" xlink:href="#path-3"></use>
|
||||
<use fill="none" xlink:href="#path-3"></use>
|
||||
</g>
|
||||
<g id="logo_googleg_48dp" sketch:type="MSLayerGroup" transform="translate(15.000000, 15.000000)">
|
||||
<path d="M17.64,9.20454545 C17.64,8.56636364 17.5827273,7.95272727 17.4763636,7.36363636 L9,7.36363636 L9,10.845 L13.8436364,10.845 C13.635,11.97 13.0009091,12.9231818 12.0477273,13.5613636 L12.0477273,15.8195455 L14.9563636,15.8195455 C16.6581818,14.2527273 17.64,11.9454545 17.64,9.20454545 L17.64,9.20454545 Z" id="Shape" fill="#4285F4" sketch:type="MSShapeGroup"></path>
|
||||
<path d="M9,18 C11.43,18 13.4672727,17.1940909 14.9563636,15.8195455 L12.0477273,13.5613636 C11.2418182,14.1013636 10.2109091,14.4204545 9,14.4204545 C6.65590909,14.4204545 4.67181818,12.8372727 3.96409091,10.71 L0.957272727,10.71 L0.957272727,13.0418182 C2.43818182,15.9831818 5.48181818,18 9,18 L9,18 Z" id="Shape" fill="#34A853" sketch:type="MSShapeGroup"></path>
|
||||
<path d="M3.96409091,10.71 C3.78409091,10.17 3.68181818,9.59318182 3.68181818,9 C3.68181818,8.40681818 3.78409091,7.83 3.96409091,7.29 L3.96409091,4.95818182 L0.957272727,4.95818182 C0.347727273,6.17318182 0,7.54772727 0,9 C0,10.4522727 0.347727273,11.8268182 0.957272727,13.0418182 L3.96409091,10.71 L3.96409091,10.71 Z" id="Shape" fill="#FBBC05" sketch:type="MSShapeGroup"></path>
|
||||
<path d="M9,3.57954545 C10.3213636,3.57954545 11.5077273,4.03363636 12.4404545,4.92545455 L15.0218182,2.34409091 C13.4631818,0.891818182 11.4259091,0 9,0 C5.48181818,0 2.43818182,2.01681818 0.957272727,4.95818182 L3.96409091,7.29 C4.67181818,5.16272727 6.65590909,3.57954545 9,3.57954545 L9,3.57954545 Z" id="Shape" fill="#EA4335" sketch:type="MSShapeGroup"></path>
|
||||
<path d="M0,0 L18,0 L18,18 L0,18 L0,0 Z" id="Shape" sketch:type="MSShapeGroup"></path>
|
||||
</g>
|
||||
<g id="handles_square" sketch:type="MSLayerGroup"></g>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 4.7 KiB |
@@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg width="46px" height="46px" viewBox="0 0 46 46" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sketch="http://www.bohemiancoding.com/sketch/ns">
|
||||
<!-- Generator: Sketch 3.3.3 (12081) - http://www.bohemiancoding.com/sketch -->
|
||||
<title>btn_google_dark_pressed_ios</title>
|
||||
<desc>Created with Sketch.</desc>
|
||||
<defs>
|
||||
<filter x="-50%" y="-50%" width="200%" height="200%" filterUnits="objectBoundingBox" id="filter-1">
|
||||
<feOffset dx="0" dy="1" in="SourceAlpha" result="shadowOffsetOuter1"></feOffset>
|
||||
<feGaussianBlur stdDeviation="0.5" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
|
||||
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.168 0" in="shadowBlurOuter1" type="matrix" result="shadowMatrixOuter1"></feColorMatrix>
|
||||
<feOffset dx="0" dy="0" in="SourceAlpha" result="shadowOffsetOuter2"></feOffset>
|
||||
<feGaussianBlur stdDeviation="0.5" in="shadowOffsetOuter2" result="shadowBlurOuter2"></feGaussianBlur>
|
||||
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.084 0" in="shadowBlurOuter2" type="matrix" result="shadowMatrixOuter2"></feColorMatrix>
|
||||
<feMerge>
|
||||
<feMergeNode in="shadowMatrixOuter1"></feMergeNode>
|
||||
<feMergeNode in="shadowMatrixOuter2"></feMergeNode>
|
||||
<feMergeNode in="SourceGraphic"></feMergeNode>
|
||||
</feMerge>
|
||||
</filter>
|
||||
<rect id="path-2" x="0" y="0" width="40" height="40" rx="2"></rect>
|
||||
<rect id="path-3" x="5" y="5" width="38" height="38" rx="1"></rect>
|
||||
</defs>
|
||||
<g id="Google-Button" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage">
|
||||
<g id="9-PATCH" sketch:type="MSArtboardGroup" transform="translate(-728.000000, -219.000000)"></g>
|
||||
<g id="btn_google_dark_pressed" sketch:type="MSArtboardGroup" transform="translate(-1.000000, -1.000000)">
|
||||
<g id="button" sketch:type="MSLayerGroup" transform="translate(4.000000, 4.000000)" filter="url(#filter-1)">
|
||||
<g id="button-bg">
|
||||
<use fill="#3367D6" fill-rule="evenodd" sketch:type="MSShapeGroup" xlink:href="#path-2"></use>
|
||||
<use fill="none" xlink:href="#path-2"></use>
|
||||
<use fill="none" xlink:href="#path-2"></use>
|
||||
<use fill="none" xlink:href="#path-2"></use>
|
||||
</g>
|
||||
</g>
|
||||
<g id="handles_square" sketch:type="MSLayerGroup"></g>
|
||||
<g id="button-bg-copy">
|
||||
<use fill="#EEEEEE" fill-rule="evenodd" sketch:type="MSShapeGroup" xlink:href="#path-3"></use>
|
||||
<use fill="none" xlink:href="#path-3"></use>
|
||||
<use fill="none" xlink:href="#path-3"></use>
|
||||
<use fill="none" xlink:href="#path-3"></use>
|
||||
</g>
|
||||
<g id="logo_googleg_48dp" sketch:type="MSLayerGroup" transform="translate(15.000000, 15.000000)">
|
||||
<path d="M17.64,9.20454545 C17.64,8.56636364 17.5827273,7.95272727 17.4763636,7.36363636 L9,7.36363636 L9,10.845 L13.8436364,10.845 C13.635,11.97 13.0009091,12.9231818 12.0477273,13.5613636 L12.0477273,15.8195455 L14.9563636,15.8195455 C16.6581818,14.2527273 17.64,11.9454545 17.64,9.20454545 L17.64,9.20454545 Z" id="Shape" fill="#4285F4" sketch:type="MSShapeGroup"></path>
|
||||
<path d="M9,18 C11.43,18 13.4672727,17.1940909 14.9563636,15.8195455 L12.0477273,13.5613636 C11.2418182,14.1013636 10.2109091,14.4204545 9,14.4204545 C6.65590909,14.4204545 4.67181818,12.8372727 3.96409091,10.71 L0.957272727,10.71 L0.957272727,13.0418182 C2.43818182,15.9831818 5.48181818,18 9,18 L9,18 Z" id="Shape" fill="#34A853" sketch:type="MSShapeGroup"></path>
|
||||
<path d="M3.96409091,10.71 C3.78409091,10.17 3.68181818,9.59318182 3.68181818,9 C3.68181818,8.40681818 3.78409091,7.83 3.96409091,7.29 L3.96409091,4.95818182 L0.957272727,4.95818182 C0.347727273,6.17318182 0,7.54772727 0,9 C0,10.4522727 0.347727273,11.8268182 0.957272727,13.0418182 L3.96409091,10.71 L3.96409091,10.71 Z" id="Shape" fill="#FBBC05" sketch:type="MSShapeGroup"></path>
|
||||
<path d="M9,3.57954545 C10.3213636,3.57954545 11.5077273,4.03363636 12.4404545,4.92545455 L15.0218182,2.34409091 C13.4631818,0.891818182 11.4259091,0 9,0 C5.48181818,0 2.43818182,2.01681818 0.957272727,4.95818182 L3.96409091,7.29 C4.67181818,5.16272727 6.65590909,3.57954545 9,3.57954545 L9,3.57954545 Z" id="Shape" fill="#EA4335" sketch:type="MSShapeGroup"></path>
|
||||
<path d="M0,0 L18,0 L18,18 L0,18 L0,0 Z" id="Shape" sketch:type="MSShapeGroup"></path>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 4.7 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
@@ -0,0 +1 @@
|
||||
<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="box-open" class="svg-inline--fa fa-box-open fa-w-20" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><path fill="currentColor" d="M425.7 256c-16.9 0-32.8-9-41.4-23.4L320 126l-64.2 106.6c-8.7 14.5-24.6 23.5-41.5 23.5-4.5 0-9-.6-13.3-1.9L64 215v178c0 14.7 10 27.5 24.2 31l216.2 54.1c10.2 2.5 20.9 2.5 31 0L551.8 424c14.2-3.6 24.2-16.4 24.2-31V215l-137 39.1c-4.3 1.3-8.8 1.9-13.3 1.9zm212.6-112.2L586.8 41c-3.1-6.2-9.8-9.8-16.7-8.9L320 64l91.7 152.1c3.8 6.3 11.4 9.3 18.5 7.3l197.9-56.5c9.9-2.9 14.7-13.9 10.2-23.1zM53.2 41L1.7 143.8c-4.6 9.2.3 20.2 10.1 23l197.9 56.5c7.1 2 14.7-1 18.5-7.3L320 64 69.8 32.1c-6.9-.8-13.5 2.7-16.6 8.9z"></path></svg>
|
||||
|
After Width: | Height: | Size: 737 B |
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"type": "application",
|
||||
"source-directories": ["./src/elm", "./elm-material/src/elm"],
|
||||
"elm-version": "0.19.1",
|
||||
"dependencies": {
|
||||
"direct": {
|
||||
"NoRedInk/elm-json-decode-pipeline": "1.0.0",
|
||||
"elm/browser": "1.0.2",
|
||||
"elm/bytes": "1.0.8",
|
||||
"elm/core": "1.0.5",
|
||||
"elm/file": "1.0.5",
|
||||
"elm/html": "1.0.0",
|
||||
"elm/http": "2.0.0",
|
||||
"elm/json": "1.1.3",
|
||||
"elm/time": "1.0.0",
|
||||
"elm/url": "1.0.0",
|
||||
"elm-community/list-extra": "8.2.4",
|
||||
"lattyware/elm-fontawesome": "4.0.0",
|
||||
"lattyware/elm-json-diff": "1.0.0",
|
||||
"norpan/elm-html5-drag-drop": "3.1.4",
|
||||
"norpan/elm-json-patch": "1.0.1"
|
||||
},
|
||||
"indirect": {
|
||||
"elm/regex": "1.0.0",
|
||||
"elm/svg": "1.0.1",
|
||||
"elm/virtual-dom": "1.0.2"
|
||||
}
|
||||
},
|
||||
"test-dependencies": {
|
||||
"direct": {},
|
||||
"indirect": {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
user nginx;
|
||||
worker_processes 1;
|
||||
|
||||
error_log /var/log/nginx/error.log warn;
|
||||
pid /var/run/nginx.pid;
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
http {
|
||||
resolver 127.0.0.11;
|
||||
|
||||
gzip on;
|
||||
gzip_static on;
|
||||
gzip_comp_level 2;
|
||||
gzip_min_length 64;
|
||||
|
||||
types {
|
||||
application/manifest+json webmanifest;
|
||||
}
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||
'$status $body_bytes_sent "$http_referer" '
|
||||
'"$http_user_agent" "$http_x_forwarded_for"';
|
||||
|
||||
access_log /var/log/nginx/access.log main;
|
||||
|
||||
sendfile on;
|
||||
tcp_nopush on;
|
||||
tcp_nodelay on;
|
||||
|
||||
keepalive_timeout 65;
|
||||
|
||||
upstream server {
|
||||
server server:8081;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 8080 default_server;
|
||||
listen [::]:8080 default_server;
|
||||
server_name _;
|
||||
|
||||
root "/usr/share/nginx/html";
|
||||
|
||||
location /api {
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_pass http://server;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "Upgrade";
|
||||
}
|
||||
|
||||
location /assets {
|
||||
expires 365d;
|
||||
}
|
||||
|
||||
location = / {
|
||||
try_files "" /index.html;
|
||||
}
|
||||
|
||||
error_page 404 /;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
{
|
||||
"name": "@manydecks/client",
|
||||
"version": "1.0.0",
|
||||
"description": "The web client to make and share custom decks for Massive Decks.",
|
||||
"scripts": {
|
||||
"dev": "npx webpack-dev-server --mode=development --port 8082",
|
||||
"build": "npx webpack --mode=production",
|
||||
"build-image": "docker build . -t \"manydecks/client\" --build-arg BUILD_DATE=\"$(date --rfc-3339=seconds)\""
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/Lattyware/manydecks.git"
|
||||
},
|
||||
"author": "Reread Games <team@rereadgames.com>",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"bugs": {
|
||||
"url": "https://github.com/Lattyware/manydecks/issues"
|
||||
},
|
||||
"homepage": "https://github.com/Lattyware/manydecks#readme",
|
||||
"dependencies": {
|
||||
"@material/card": "^6.0.0",
|
||||
"@material/mwc-button": "^0.15.0",
|
||||
"@material/mwc-fab": "^0.15.0",
|
||||
"@material/mwc-icon-button": "^0.15.0",
|
||||
"@material/mwc-linear-progress": "^0.15.0",
|
||||
"@material/mwc-list": "^0.15.0",
|
||||
"@material/mwc-menu": "^0.15.0",
|
||||
"@material/mwc-select": "^0.15.0",
|
||||
"@material/mwc-slider": "^0.15.0",
|
||||
"@material/mwc-switch": "^0.15.0",
|
||||
"@material/mwc-tab": "^0.15.0",
|
||||
"@material/mwc-tab-bar": "^0.15.0",
|
||||
"@material/mwc-textarea": "^0.15.0",
|
||||
"@material/mwc-textfield": "^0.15.0",
|
||||
"@webcomponents/webcomponentsjs": "^2.4.3",
|
||||
"json5": "^2.1.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/gapi": "0.0.39",
|
||||
"@types/gapi.auth2": "0.0.52",
|
||||
"@types/json5": "0.0.30",
|
||||
"css-loader": "^3.5.3",
|
||||
"elm": "^0.19.1-3",
|
||||
"elm-webpack-loader": "^6.0.1",
|
||||
"extract-loader": "^5.0.1",
|
||||
"file-loader": "^6.0.0",
|
||||
"html-loader": "^1.1.0",
|
||||
"html-webpack-plugin": "^4.3.0",
|
||||
"prettier": "^2.0.5",
|
||||
"prettier-plugin-elm": "^0.7.0",
|
||||
"resolve-url-loader": "^3.1.1",
|
||||
"sass": "^1.26.5",
|
||||
"sass-loader": "^8.0.2",
|
||||
"ts-loader": "^7.0.4",
|
||||
"typescript": "^3.9.2",
|
||||
"webpack": "^4.43.0",
|
||||
"webpack-cli": "^3.3.11",
|
||||
"webpack-dev-server": "^3.11.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
module Cards.Call exposing
|
||||
( Call
|
||||
, Line
|
||||
, decode
|
||||
, editor
|
||||
, editorToCall
|
||||
, encode
|
||||
, fromStrings
|
||||
, init
|
||||
, toString
|
||||
, type_
|
||||
, view
|
||||
)
|
||||
|
||||
import Cards.Call.Part as Part
|
||||
import Cards.Call.Part.Model as Part exposing (Part)
|
||||
import Cards.Call.Style as Style
|
||||
import Cards.Call.Transform as Transform
|
||||
import Cards.Card as Card
|
||||
import Cards.Response exposing (Response)
|
||||
import Cards.Type as Type exposing (Type)
|
||||
import Html exposing (Html)
|
||||
import Json.Decode as Json
|
||||
import Json.Encode
|
||||
import List.Extra as List
|
||||
import ManyDecks.Pages.Edit.CallEditor.Model as Editor exposing (Atom(..))
|
||||
|
||||
|
||||
type Call
|
||||
= Call (List Line)
|
||||
|
||||
|
||||
type alias Line =
|
||||
List Part
|
||||
|
||||
|
||||
type_ : Type Call
|
||||
type_ =
|
||||
Type.Call
|
||||
|
||||
|
||||
init : Call
|
||||
init =
|
||||
Call [ [ Part.Slot Transform.None Style.None ] ]
|
||||
|
||||
|
||||
view : List Response -> Card.Side -> Call -> Html msg
|
||||
view fill side (Call lines) =
|
||||
let
|
||||
folder row part ( f, column, soFar ) =
|
||||
let
|
||||
( rendered, rest ) =
|
||||
Part.view f part
|
||||
in
|
||||
( rest, column + 1, rendered :: soFar )
|
||||
|
||||
lineFolder line ( f, row, soFar ) =
|
||||
let
|
||||
( rest, _, lineContent ) =
|
||||
line |> List.foldr (folder row) ( f, 0, [] )
|
||||
in
|
||||
( rest, row + 1, Html.p [] lineContent :: soFar )
|
||||
|
||||
( _, _, content ) =
|
||||
lines |> List.foldr lineFolder ( fill, 0, [] )
|
||||
in
|
||||
Card.view type_ Card.Immutable content side
|
||||
|
||||
|
||||
toString : String -> List Response -> Call -> String
|
||||
toString lineBreak _ (Call lines) =
|
||||
let
|
||||
toBasic part =
|
||||
case part of
|
||||
Part.Slot _ _ ->
|
||||
"_"
|
||||
|
||||
Part.Text text _ ->
|
||||
text
|
||||
in
|
||||
lines |> List.map (List.map toBasic) |> List.intersperse [ lineBreak ] |> List.concat |> String.concat
|
||||
|
||||
|
||||
fromStrings : List String -> Call
|
||||
fromStrings strings =
|
||||
strings
|
||||
|> List.map (\t -> Part.Text t Style.None)
|
||||
|> List.intersperse (Part.Slot Transform.None Style.None)
|
||||
|> (\p -> Call [ p ])
|
||||
|
||||
|
||||
decode : Json.Decoder Call
|
||||
decode =
|
||||
let
|
||||
line =
|
||||
Json.list Part.decode
|
||||
in
|
||||
Json.list line |> Json.map Call
|
||||
|
||||
|
||||
encode : Call -> Json.Value
|
||||
encode (Call call) =
|
||||
let
|
||||
line =
|
||||
Json.Encode.list Part.encode
|
||||
in
|
||||
call |> Json.Encode.list line
|
||||
|
||||
|
||||
editor : Call -> Editor.Model
|
||||
editor (Call lines) =
|
||||
{ atoms = lines |> List.map (List.concatMap partToAtoms) |> List.intersperse [ NewLine ] |> List.concat
|
||||
, selection = Nothing
|
||||
, selecting = Nothing
|
||||
, moving = Nothing
|
||||
, hover = Nothing
|
||||
, cursor = 0
|
||||
, styled = []
|
||||
, control = False
|
||||
}
|
||||
|
||||
|
||||
partToAtoms : Part -> List Editor.Atom
|
||||
partToAtoms part =
|
||||
case part of
|
||||
Part.Text text style ->
|
||||
text |> String.toList |> List.map Editor.Letter
|
||||
|
||||
Part.Slot transform style ->
|
||||
[ Editor.Slot transform style ]
|
||||
|
||||
|
||||
editorToCall : Editor.Model -> Result String Call
|
||||
editorToCall { atoms } =
|
||||
let
|
||||
parts =
|
||||
atoms |> List.groupWhile (\a b -> b /= NewLine) |> List.map atomsToParts
|
||||
in
|
||||
if parts |> List.any (List.any Part.isSlot) then
|
||||
parts |> Call |> Ok
|
||||
|
||||
else
|
||||
"Calls must contain at least one slot." |> Err
|
||||
|
||||
|
||||
atomsToParts : ( Editor.Atom, List Editor.Atom ) -> List Part
|
||||
atomsToParts ( f, r ) =
|
||||
let
|
||||
atoms =
|
||||
f :: r
|
||||
|
||||
group a b =
|
||||
case a of
|
||||
Letter _ ->
|
||||
case b of
|
||||
Letter _ ->
|
||||
True
|
||||
|
||||
_ ->
|
||||
False
|
||||
|
||||
_ ->
|
||||
False
|
||||
|
||||
toChar atom =
|
||||
case atom of
|
||||
Letter char ->
|
||||
Just char
|
||||
|
||||
_ ->
|
||||
Nothing
|
||||
|
||||
toPart ( first, rest ) =
|
||||
case first of
|
||||
Letter _ ->
|
||||
(first :: rest)
|
||||
|> List.filterMap toChar
|
||||
|> String.fromList
|
||||
|> (\t -> Part.Text t Style.None |> Just)
|
||||
|
||||
Slot transform style ->
|
||||
Part.Slot transform style |> Just
|
||||
|
||||
_ ->
|
||||
Nothing
|
||||
in
|
||||
atoms |> List.groupWhile group |> List.filterMap toPart
|
||||
@@ -0,0 +1,115 @@
|
||||
module Cards.Call.Part exposing
|
||||
( decode
|
||||
, encode
|
||||
, isSlot
|
||||
, view
|
||||
)
|
||||
|
||||
import Cards.Call.Part.Model exposing (Part(..))
|
||||
import Cards.Call.Style as Style exposing (Style)
|
||||
import Cards.Call.Transform as Transform exposing (Transform)
|
||||
import Cards.Response as Response exposing (Response(..))
|
||||
import Html exposing (Html)
|
||||
import Html.Attributes as HtmlA
|
||||
import Json.Decode as Json
|
||||
import Json.Decode.Pipeline as Json
|
||||
import Json.Encode
|
||||
|
||||
|
||||
view : List Response -> Part -> ( Html msg, List Response )
|
||||
view fill part =
|
||||
let
|
||||
splitWords string =
|
||||
case String.uncons string of
|
||||
Nothing ->
|
||||
[]
|
||||
|
||||
Just ( first, rest ) ->
|
||||
case first of
|
||||
' ' ->
|
||||
String.fromChar first :: splitWords rest
|
||||
|
||||
other ->
|
||||
case splitWords rest of
|
||||
[] ->
|
||||
[ String.fromChar other ]
|
||||
|
||||
head :: tail ->
|
||||
String.cons other head :: tail
|
||||
|
||||
viewText text =
|
||||
text |> splitWords |> List.map (\t -> Html.span [] [ Html.text t ])
|
||||
in
|
||||
case part of
|
||||
Text text style ->
|
||||
( Style.toNode style [ HtmlA.class "text" ] (viewText text), fill )
|
||||
|
||||
Slot transform style ->
|
||||
let
|
||||
( emptyAttr, text, restOfFill ) =
|
||||
case fill of
|
||||
r :: rest ->
|
||||
( [], r |> Response.toString |> viewText, rest )
|
||||
|
||||
[] ->
|
||||
( [ HtmlA.class "empty" ], [], [] )
|
||||
|
||||
attrs =
|
||||
List.concat [ [ HtmlA.class "slot" ], emptyAttr, Transform.toAttributes transform ]
|
||||
in
|
||||
( Style.toNode style attrs text, restOfFill )
|
||||
|
||||
|
||||
decode : Json.Decoder Part
|
||||
decode =
|
||||
let
|
||||
slot =
|
||||
Json.succeed Slot
|
||||
|> Json.optional "transform" Transform.decode Transform.None
|
||||
|> Json.optional "style" Style.decode Style.None
|
||||
|
||||
styled =
|
||||
Json.succeed Text
|
||||
|> Json.required "text" Json.string
|
||||
|> Json.optional "style" Style.decode Style.None
|
||||
in
|
||||
Json.oneOf
|
||||
[ Json.string |> Json.map (\t -> Text t Style.None)
|
||||
, styled
|
||||
, slot
|
||||
]
|
||||
|
||||
|
||||
encode : Part -> Json.Value
|
||||
encode part =
|
||||
let
|
||||
maybeField field =
|
||||
case field of
|
||||
( n, Just v ) ->
|
||||
Just ( n, v )
|
||||
|
||||
( _, Nothing ) ->
|
||||
Nothing
|
||||
|
||||
maybeObject =
|
||||
List.filterMap maybeField >> Json.Encode.object
|
||||
in
|
||||
case part of
|
||||
Text text Style.None ->
|
||||
text |> Json.Encode.string
|
||||
|
||||
Text text s ->
|
||||
maybeObject [ ( "text", text |> Json.Encode.string |> Just ), ( "style", s |> Style.encode ) ]
|
||||
|
||||
Slot t s ->
|
||||
maybeObject [ ( "transform", t |> Transform.encode ), ( "style", s |> Style.encode ) ]
|
||||
|
||||
|
||||
isSlot : Part -> Bool
|
||||
isSlot part =
|
||||
case part of
|
||||
Text string style ->
|
||||
False
|
||||
|
||||
Slot transform style ->
|
||||
True
|
||||
@@ -0,0 +1,9 @@
|
||||
module Cards.Call.Part.Model exposing (..)
|
||||
|
||||
import Cards.Call.Style exposing (Style)
|
||||
import Cards.Call.Transform exposing (Transform)
|
||||
|
||||
|
||||
type Part
|
||||
= Text String Style
|
||||
| Slot Transform Style
|
||||
@@ -0,0 +1,53 @@
|
||||
module Cards.Call.Style exposing
|
||||
( Style(..)
|
||||
, decode
|
||||
, encode
|
||||
, toNode
|
||||
)
|
||||
|
||||
import Html exposing (Html)
|
||||
import Json.Decode as Json
|
||||
import Json.Encode
|
||||
|
||||
|
||||
type Style
|
||||
= None
|
||||
| Em
|
||||
|
||||
|
||||
toNode : Style -> (List (Html.Attribute msg) -> List (Html msg) -> Html msg)
|
||||
toNode style =
|
||||
case style of
|
||||
None ->
|
||||
Html.span
|
||||
|
||||
Em ->
|
||||
Html.em
|
||||
|
||||
|
||||
decode : Json.Decoder Style
|
||||
decode =
|
||||
let
|
||||
byName name =
|
||||
case name of
|
||||
"Em" ->
|
||||
Json.succeed Em
|
||||
|
||||
_ ->
|
||||
"Unknown style: " ++ name |> Json.fail
|
||||
in
|
||||
Json.string |> Json.andThen byName
|
||||
|
||||
|
||||
encode : Style -> Maybe Json.Value
|
||||
encode s =
|
||||
let
|
||||
name =
|
||||
case s of
|
||||
None ->
|
||||
Nothing
|
||||
|
||||
Em ->
|
||||
Just "Em"
|
||||
in
|
||||
name |> Maybe.map Json.Encode.string
|
||||
@@ -0,0 +1,64 @@
|
||||
module Cards.Call.Transform exposing
|
||||
( Transform(..)
|
||||
, decode
|
||||
, encode
|
||||
, toAttributes
|
||||
)
|
||||
|
||||
import Html
|
||||
import Html.Attributes as HtmlA
|
||||
import Json.Decode as Json
|
||||
import Json.Encode
|
||||
|
||||
|
||||
type Transform
|
||||
= None
|
||||
| UpperCase
|
||||
| Capitalize
|
||||
|
||||
|
||||
toAttributes : Transform -> List (Html.Attribute msg)
|
||||
toAttributes style =
|
||||
case style of
|
||||
None ->
|
||||
[]
|
||||
|
||||
UpperCase ->
|
||||
[ HtmlA.class "upper-case" ]
|
||||
|
||||
Capitalize ->
|
||||
[ HtmlA.class "capitalize" ]
|
||||
|
||||
|
||||
decode : Json.Decoder Transform
|
||||
decode =
|
||||
let
|
||||
byName name =
|
||||
case name of
|
||||
"UpperCase" ->
|
||||
Json.succeed UpperCase
|
||||
|
||||
"Capitalize" ->
|
||||
Json.succeed Capitalize
|
||||
|
||||
_ ->
|
||||
"Unknown transform: " ++ name |> Json.fail
|
||||
in
|
||||
Json.string |> Json.andThen byName
|
||||
|
||||
|
||||
encode : Transform -> Maybe Json.Value
|
||||
encode t =
|
||||
let
|
||||
name =
|
||||
case t of
|
||||
None ->
|
||||
Nothing
|
||||
|
||||
Capitalize ->
|
||||
Just "Capitalize"
|
||||
|
||||
UpperCase ->
|
||||
Just "UpperCase"
|
||||
in
|
||||
name |> Maybe.map Json.Encode.string
|
||||
@@ -0,0 +1,74 @@
|
||||
module Cards.Card exposing
|
||||
( Mutability(..)
|
||||
, Side(..)
|
||||
, view
|
||||
)
|
||||
|
||||
import Cards.Type as Type exposing (Type)
|
||||
import Html exposing (Html)
|
||||
import Html.Attributes as HtmlA
|
||||
|
||||
|
||||
type Mutability value msg
|
||||
= Immutable
|
||||
| Mutable (value -> msg)
|
||||
|
||||
|
||||
type Side
|
||||
= Face
|
||||
| Reverse
|
||||
|
||||
|
||||
view : Type value -> Mutability value msg -> List (Html msg) -> Side -> Html msg
|
||||
view type_ mutability content visibleSide =
|
||||
let
|
||||
mutabilityClass =
|
||||
case mutability of
|
||||
Immutable ->
|
||||
"immutable"
|
||||
|
||||
Mutable _ ->
|
||||
"mutable"
|
||||
|
||||
typeClass =
|
||||
case type_ of
|
||||
Type.Call ->
|
||||
"call"
|
||||
|
||||
Type.Response ->
|
||||
"response"
|
||||
|
||||
visibleSideClass =
|
||||
case visibleSide of
|
||||
Face ->
|
||||
"face-up"
|
||||
|
||||
Reverse ->
|
||||
"face-down"
|
||||
|
||||
viewSide side primary secondary =
|
||||
let
|
||||
sideClass =
|
||||
case side of
|
||||
Face ->
|
||||
"face"
|
||||
|
||||
Reverse ->
|
||||
"reverse"
|
||||
in
|
||||
Html.div [ HtmlA.classList [ ( "side", True ), ( sideClass, True ) ] ]
|
||||
[ Html.div [ HtmlA.class "primary-content" ] primary
|
||||
, Html.div [ HtmlA.class "secondary-content" ] secondary
|
||||
]
|
||||
in
|
||||
Html.div
|
||||
[ HtmlA.classList
|
||||
[ ( "game-card", True )
|
||||
, ( typeClass, True )
|
||||
, ( visibleSideClass, True )
|
||||
, ( mutabilityClass, True )
|
||||
]
|
||||
]
|
||||
[ viewSide Reverse [ Html.text "Massive", Html.text "Decks" ] []
|
||||
, viewSide Face content []
|
||||
]
|
||||
@@ -0,0 +1,64 @@
|
||||
module Cards.Deck exposing
|
||||
( Deck
|
||||
, decode
|
||||
, empty
|
||||
, encode
|
||||
)
|
||||
|
||||
import Cards.Call as Call exposing (Call)
|
||||
import Cards.Response as Response exposing (Response)
|
||||
import Json.Decode as Json
|
||||
import Json.Decode.Pipeline as Json
|
||||
import Json.Encode
|
||||
|
||||
|
||||
type alias Deck =
|
||||
{ name : String
|
||||
, language : Maybe String
|
||||
, author : Maybe String
|
||||
, calls : List Call
|
||||
, responses : List Response
|
||||
}
|
||||
|
||||
|
||||
empty : Deck
|
||||
empty =
|
||||
{ name = "New Deck"
|
||||
, language = Nothing
|
||||
, author = Nothing
|
||||
, calls = []
|
||||
, responses = []
|
||||
}
|
||||
|
||||
|
||||
encode : Deck -> Json.Value
|
||||
encode deck =
|
||||
let
|
||||
maybeField field =
|
||||
case field of
|
||||
( n, Just v ) ->
|
||||
Just ( n, v )
|
||||
|
||||
( _, Nothing ) ->
|
||||
Nothing
|
||||
|
||||
maybeObject =
|
||||
List.filterMap maybeField >> Json.Encode.object
|
||||
in
|
||||
maybeObject
|
||||
[ ( "name", Json.Encode.string deck.name |> Just )
|
||||
, ( "language", deck.language |> Maybe.map Json.Encode.string )
|
||||
, ( "author", deck.author |> Maybe.map Json.Encode.string )
|
||||
, ( "calls", deck.calls |> Json.Encode.list Call.encode |> Just )
|
||||
, ( "responses", deck.responses |> Json.Encode.list Response.encode |> Just )
|
||||
]
|
||||
|
||||
|
||||
decode : Json.Decoder Deck
|
||||
decode =
|
||||
Json.succeed Deck
|
||||
|> Json.required "name" Json.string
|
||||
|> Json.optional "language" (Json.string |> Json.map Just) Nothing
|
||||
|> Json.optional "author" (Json.string |> Json.map Just) Nothing
|
||||
|> Json.required "calls" (Json.list Call.decode)
|
||||
|> Json.required "responses" (Json.list Response.decode)
|
||||
@@ -0,0 +1,71 @@
|
||||
module Cards.Response exposing
|
||||
( Response
|
||||
, decode
|
||||
, encode
|
||||
, fromString
|
||||
, init
|
||||
, toString
|
||||
, view
|
||||
)
|
||||
|
||||
import Cards.Card as Card
|
||||
import Cards.Type as Type exposing (Type)
|
||||
import Html exposing (Html)
|
||||
import Html.Attributes as HtmlA
|
||||
import Html.Events as HtmlE
|
||||
import Json.Decode as Json
|
||||
import Json.Encode
|
||||
|
||||
|
||||
type Response
|
||||
= Response String
|
||||
|
||||
|
||||
type_ : Type Response
|
||||
type_ =
|
||||
Type.Response
|
||||
|
||||
|
||||
init : Response
|
||||
init =
|
||||
Response ""
|
||||
|
||||
|
||||
view : Card.Mutability Response msg -> Card.Side -> Response -> Html msg
|
||||
view mutability side (Response text) =
|
||||
let
|
||||
content =
|
||||
case mutability of
|
||||
Card.Immutable ->
|
||||
[ Html.text text ]
|
||||
|
||||
Card.Mutable update ->
|
||||
[ Html.textarea
|
||||
[ HtmlA.value text
|
||||
, HtmlE.onInput (Response >> update)
|
||||
, HtmlA.placeholder "type a response here"
|
||||
]
|
||||
[]
|
||||
]
|
||||
in
|
||||
Card.view type_ mutability content side
|
||||
|
||||
|
||||
toString : Response -> String
|
||||
toString (Response text) =
|
||||
text
|
||||
|
||||
|
||||
fromString : String -> Response
|
||||
fromString text =
|
||||
Response text
|
||||
|
||||
|
||||
encode : Response -> Json.Value
|
||||
encode (Response response) =
|
||||
response |> Json.Encode.string
|
||||
|
||||
|
||||
decode : Json.Decoder Response
|
||||
decode =
|
||||
Json.string |> Json.map Response
|
||||
@@ -0,0 +1,6 @@
|
||||
module Cards.Type exposing (Type(..))
|
||||
|
||||
|
||||
type Type value
|
||||
= Call
|
||||
| Response
|
||||
@@ -0,0 +1,391 @@
|
||||
module ManyDecks exposing (..)
|
||||
|
||||
import Browser
|
||||
import Browser.Navigation as Navigation
|
||||
import Cards.Deck as Deck
|
||||
import File
|
||||
import File.Download as File
|
||||
import File.Select as File
|
||||
import FontAwesome.Icon as Icon
|
||||
import FontAwesome.Solid as Icon
|
||||
import FontAwesome.Styles as Icon
|
||||
import Html
|
||||
import Html.Attributes as HtmlA
|
||||
import Http
|
||||
import Json.Decode as Json
|
||||
import ManyDecks.Auth exposing (Auth)
|
||||
import ManyDecks.Error as Error exposing (Error)
|
||||
import ManyDecks.Google as Google
|
||||
import ManyDecks.Messages exposing (Msg(..))
|
||||
import ManyDecks.Pages.Decks as Decks
|
||||
import ManyDecks.Pages.Decks.Model as Decks
|
||||
import ManyDecks.Pages.Edit as Edit
|
||||
import ManyDecks.Pages.Edit.Model as Edit
|
||||
import ManyDecks.Pages.Login as Login
|
||||
import ManyDecks.Pages.Profile as Profile
|
||||
import ManyDecks.Pages.Profile.Model as Profile
|
||||
import ManyDecks.Ports as Ports
|
||||
import Material.Button as Button
|
||||
import Task
|
||||
import Url exposing (Url)
|
||||
|
||||
|
||||
type alias Flags =
|
||||
{ auth : Maybe Auth }
|
||||
|
||||
|
||||
type alias Model =
|
||||
{ core : Maybe CoreModel
|
||||
, error : Maybe Error
|
||||
}
|
||||
|
||||
|
||||
type alias CoreModel =
|
||||
{ auth : Auth
|
||||
, decks : Maybe (List Decks.CodeAndSummary)
|
||||
, profile : Profile.Model
|
||||
, edit : Maybe Edit.Model
|
||||
}
|
||||
|
||||
|
||||
initCore auth =
|
||||
{ auth = auth, decks = Nothing, profile = Profile.init auth, edit = Nothing }
|
||||
|
||||
|
||||
main : Program Flags Model Msg
|
||||
main =
|
||||
Browser.application
|
||||
{ init = init
|
||||
, view = view
|
||||
, update = update
|
||||
, subscriptions = subscriptions
|
||||
, onUrlRequest = onUrlRequest
|
||||
, onUrlChange = onUrlChange
|
||||
}
|
||||
|
||||
|
||||
init : Flags -> Url -> Navigation.Key -> ( Model, Cmd Msg )
|
||||
init flags url key =
|
||||
( { core = flags.auth |> Maybe.map initCore, error = Nothing }
|
||||
, case flags.auth of
|
||||
Just auth ->
|
||||
Decks.getDecks auth.token decksFromResult
|
||||
|
||||
Nothing ->
|
||||
Cmd.none
|
||||
)
|
||||
|
||||
|
||||
subscriptions : Model -> Sub Msg
|
||||
subscriptions model =
|
||||
let
|
||||
googleAuthResultToMessage value =
|
||||
case value |> Json.decodeValue Google.authResult of
|
||||
Ok (Ok code) ->
|
||||
GoogleAuthResult code
|
||||
|
||||
Ok (Err error) ->
|
||||
error |> Error
|
||||
|
||||
Err error ->
|
||||
error |> Json.errorToString |> Error
|
||||
|
||||
json5DecodedToMessage value =
|
||||
case value |> Json.decodeValue Deck.decode of
|
||||
Ok deck ->
|
||||
NewDeck deck
|
||||
|
||||
Err error ->
|
||||
error |> Json.errorToString |> Error
|
||||
in
|
||||
Sub.batch
|
||||
[ Ports.googleAuthResult googleAuthResultToMessage
|
||||
, Ports.json5Decoded json5DecodedToMessage
|
||||
, model.core |> Maybe.andThen .edit |> Maybe.map (Edit.subscriptions EditMsg) |> Maybe.withDefault Sub.none
|
||||
]
|
||||
|
||||
|
||||
onUrlRequest : Browser.UrlRequest -> Msg
|
||||
onUrlRequest urlRequest =
|
||||
NoOp
|
||||
|
||||
|
||||
onUrlChange : Url -> Msg
|
||||
onUrlChange url =
|
||||
NoOp
|
||||
|
||||
|
||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||
update msg model =
|
||||
case msg of
|
||||
SetError error ->
|
||||
( { model | error = Just error }, Cmd.none )
|
||||
|
||||
TryGoogleAuth ->
|
||||
( model, Ports.tryGoogleAuth () )
|
||||
|
||||
GoogleAuthResult code ->
|
||||
let
|
||||
authFromGoogleCode result =
|
||||
case result of
|
||||
Ok token ->
|
||||
MdAuthResult token
|
||||
|
||||
Err error ->
|
||||
error |> Error.Http |> SetError
|
||||
in
|
||||
( model, Google.signIn code authFromGoogleCode )
|
||||
|
||||
MdAuthResult auth ->
|
||||
( { model | core = auth |> initCore |> Just }
|
||||
, Cmd.batch
|
||||
[ Decks.getDecks auth.token decksFromResult
|
||||
, auth |> Just |> Ports.storeAuth
|
||||
]
|
||||
)
|
||||
|
||||
ReceiveDecks decks ->
|
||||
let
|
||||
add m =
|
||||
{ m | decks = Just decks }
|
||||
in
|
||||
( { model | core = model.core |> Maybe.map add }, Cmd.none )
|
||||
|
||||
UploadDeck ->
|
||||
( model, File.file [ ".deck.json5" ] UploadedDeck )
|
||||
|
||||
UploadedDeck file ->
|
||||
( model, file |> File.toString |> Task.perform Json5Parse )
|
||||
|
||||
Json5Parse raw ->
|
||||
( model, Ports.json5Decode raw )
|
||||
|
||||
NewDeck d ->
|
||||
let
|
||||
token =
|
||||
model.core |> Maybe.map (.auth >> .token) |> Maybe.withDefault ""
|
||||
|
||||
newDeck result =
|
||||
case result of
|
||||
Ok code ->
|
||||
EditDeck code (Just d) True
|
||||
|
||||
Err error ->
|
||||
error |> Error.Http |> SetError
|
||||
in
|
||||
( model, Decks.createDeck token d newDeck )
|
||||
|
||||
EditDeck code deck needsToBeAdded ->
|
||||
case deck of
|
||||
Just d ->
|
||||
case model.core of
|
||||
Just m ->
|
||||
let
|
||||
decks =
|
||||
if needsToBeAdded then
|
||||
let
|
||||
summary =
|
||||
{ details =
|
||||
{ name = d.name
|
||||
, author = d.author |> Maybe.withDefault m.auth.name
|
||||
, language = d.language
|
||||
}
|
||||
, calls = d.calls |> List.length
|
||||
, responses = d.responses |> List.length
|
||||
, version = 0
|
||||
}
|
||||
in
|
||||
m.decks |> Maybe.map (\ds -> ds ++ [ { code = code, summary = summary } ])
|
||||
|
||||
else
|
||||
m.decks
|
||||
in
|
||||
( { model | core = Just { m | edit = Edit.init code d |> Just, decks = decks } }, Cmd.none )
|
||||
|
||||
Nothing ->
|
||||
( model, Cmd.none )
|
||||
|
||||
Nothing ->
|
||||
let
|
||||
handle result =
|
||||
case result of
|
||||
Ok d ->
|
||||
EditDeck code (Just d) needsToBeAdded
|
||||
|
||||
Err error ->
|
||||
error |> Error.Http |> SetError
|
||||
in
|
||||
( model, Decks.getDeck code handle )
|
||||
|
||||
BackFromEdit ->
|
||||
case model.core of
|
||||
Just m ->
|
||||
( { model | core = Just { m | edit = Nothing } }, Cmd.none )
|
||||
|
||||
Nothing ->
|
||||
( model, Cmd.none )
|
||||
|
||||
Delete code ->
|
||||
case model.core of
|
||||
Just m ->
|
||||
let
|
||||
newDecks =
|
||||
m.decks |> Maybe.map (List.filter (\d -> d.code /= code))
|
||||
in
|
||||
( { model | core = Just { m | decks = newDecks, edit = Nothing } }
|
||||
, Decks.deleteDeck m.auth.token code
|
||||
)
|
||||
|
||||
Nothing ->
|
||||
( model, Cmd.none )
|
||||
|
||||
Save code patch ->
|
||||
case model.core of
|
||||
Just m ->
|
||||
let
|
||||
handle result =
|
||||
case result of
|
||||
Ok () ->
|
||||
BackFromEdit
|
||||
|
||||
Err error ->
|
||||
error |> Error.Http |> SetError
|
||||
in
|
||||
( model, Decks.save m.auth.token code patch handle )
|
||||
|
||||
Nothing ->
|
||||
( model, Cmd.none )
|
||||
|
||||
Copy id ->
|
||||
( model, Ports.copy id )
|
||||
|
||||
ProfileMsg profileMsg ->
|
||||
case model.core of
|
||||
Just m ->
|
||||
let
|
||||
( newP, cmd ) =
|
||||
m.profile |> Profile.update SignOut UpdateAuth ProfileMsg m.auth.token profileMsg
|
||||
in
|
||||
( { model | core = Just { m | profile = newP } }, cmd )
|
||||
|
||||
Nothing ->
|
||||
( model, Cmd.none )
|
||||
|
||||
EditMsg editMsg ->
|
||||
case model.core of
|
||||
Just m ->
|
||||
case m.edit of
|
||||
Just e ->
|
||||
let
|
||||
( newE, cmd ) =
|
||||
Edit.update editMsg e
|
||||
in
|
||||
( { model | core = Just { m | edit = Just newE } }, cmd )
|
||||
|
||||
Nothing ->
|
||||
( model, Cmd.none )
|
||||
|
||||
Nothing ->
|
||||
( model, Cmd.none )
|
||||
|
||||
Backup ->
|
||||
let
|
||||
handleResult result =
|
||||
case result of
|
||||
Ok file ->
|
||||
DownloadBytes file
|
||||
|
||||
Err error ->
|
||||
error |> Error.Http |> SetError
|
||||
|
||||
cmd =
|
||||
model.core |> Maybe.map (\m -> Decks.backup m.auth.token handleResult) |> Maybe.withDefault Cmd.none
|
||||
in
|
||||
( model, cmd )
|
||||
|
||||
DownloadBytes bytes ->
|
||||
( model, File.bytes "backup.zip" "application/zip" bytes )
|
||||
|
||||
UpdateAuth newAuth ->
|
||||
case model.core of
|
||||
Just m ->
|
||||
( { model | core = Just { m | auth = newAuth } }, newAuth |> Just |> Ports.storeAuth )
|
||||
|
||||
Nothing ->
|
||||
( model, Cmd.none )
|
||||
|
||||
SignOut ->
|
||||
( { model | core = Nothing }, Ports.storeAuth Nothing )
|
||||
|
||||
Error _ ->
|
||||
( model, Cmd.none )
|
||||
|
||||
NoOp ->
|
||||
( model, Cmd.none )
|
||||
|
||||
|
||||
view : Model -> Browser.Document Msg
|
||||
view model =
|
||||
let
|
||||
error =
|
||||
Error.view model.error
|
||||
|
||||
body =
|
||||
case model.core of
|
||||
Nothing ->
|
||||
[ Html.div [ HtmlA.class "content" ] [ Login.view ] ]
|
||||
|
||||
Just m ->
|
||||
let
|
||||
content =
|
||||
if m.profile.viewing then
|
||||
Profile.view ProfileMsg Backup m.auth m.profile
|
||||
|
||||
else
|
||||
case m.edit of
|
||||
Just edit ->
|
||||
Edit.view BackFromEdit Save Delete EditMsg edit
|
||||
|
||||
Nothing ->
|
||||
Decks.view m.decks
|
||||
in
|
||||
[ generalNav m
|
||||
, Html.div [ HtmlA.class "content" ] content
|
||||
]
|
||||
in
|
||||
{ title = "Many Decks"
|
||||
, body = Icon.css :: error :: body
|
||||
}
|
||||
|
||||
|
||||
generalNav model =
|
||||
let
|
||||
viewProfile =
|
||||
model.profile.viewing |> not |> Profile.SetViewingProfile |> ProfileMsg
|
||||
in
|
||||
Html.nav []
|
||||
[ Html.div [ HtmlA.id "sign-out" ]
|
||||
[ Button.view Button.Standard
|
||||
Button.Padded
|
||||
"Sign Out"
|
||||
(Icon.signOutAlt |> Icon.viewIcon |> Just)
|
||||
(Just SignOut)
|
||||
]
|
||||
, Html.div [ HtmlA.id "view-profile" ]
|
||||
[ Button.view Button.Standard
|
||||
Button.Padded
|
||||
(model.auth.name ++ "'s Profile")
|
||||
(Icon.userCircle |> Icon.viewIcon |> Just)
|
||||
(Just viewProfile)
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
decksFromResult : Result Http.Error (List Decks.CodeAndSummary) -> Msg
|
||||
decksFromResult result =
|
||||
case result of
|
||||
Ok token ->
|
||||
ReceiveDecks token
|
||||
|
||||
Err error ->
|
||||
error |> Error.Http |> SetError
|
||||
@@ -0,0 +1,25 @@
|
||||
module ManyDecks.Auth exposing
|
||||
( Auth
|
||||
, Token
|
||||
, decoder
|
||||
)
|
||||
|
||||
import Json.Decode as Json
|
||||
import Json.Decode.Pipeline as Json
|
||||
|
||||
|
||||
type alias Token =
|
||||
String
|
||||
|
||||
|
||||
type alias Auth =
|
||||
{ token : Token
|
||||
, name : String
|
||||
}
|
||||
|
||||
|
||||
decoder : Json.Decoder Auth
|
||||
decoder =
|
||||
Json.succeed Auth
|
||||
|> Json.required "token" Json.string
|
||||
|> Json.required "name" Json.string
|
||||
@@ -0,0 +1,61 @@
|
||||
module ManyDecks.Error exposing (..)
|
||||
|
||||
import Html exposing (Html)
|
||||
import Html.Attributes as HtmlA
|
||||
import Http
|
||||
import Json.Decode as Json
|
||||
import Material.Card as Card
|
||||
|
||||
|
||||
type Error
|
||||
= Http Http.Error
|
||||
| Json Json.Error
|
||||
|
||||
|
||||
view : Maybe Error -> Html msg
|
||||
view error =
|
||||
case error of
|
||||
Just e ->
|
||||
Html.div [ HtmlA.class "core-error" ]
|
||||
[ Card.view []
|
||||
[ Html.p [] [ Html.text "Sorry, there appears to have been a problem, please try refreshing the page." ]
|
||||
, Html.p [] [ e |> message |> Html.text ]
|
||||
]
|
||||
]
|
||||
|
||||
Nothing ->
|
||||
Html.text ""
|
||||
|
||||
|
||||
message : Error -> String
|
||||
message error =
|
||||
case error of
|
||||
Http e ->
|
||||
case e of
|
||||
Http.BadUrl url ->
|
||||
"Application bug: Tried to access “" ++ url ++ "” which isn't a valid URL."
|
||||
|
||||
Http.Timeout ->
|
||||
"Timed out trying to connect to the server, it is probably down. Try again after a short delay."
|
||||
|
||||
Http.NetworkError ->
|
||||
"Could not connect to the server. Please check your internet connection and try again."
|
||||
|
||||
Http.BadStatus status ->
|
||||
if status == 504 || status == 502 then
|
||||
"The server appears to be down. Try again after a short delay."
|
||||
|
||||
else if status >= 400 && status < 500 then
|
||||
"The server rejected that, please check for problems."
|
||||
|
||||
else if status >= 500 && status < 600 then
|
||||
"There was a problem with the server."
|
||||
|
||||
else
|
||||
"The server returned an expected response."
|
||||
|
||||
Http.BadBody description ->
|
||||
"We got a response we didn't expect from the server: " ++ description
|
||||
|
||||
Json e ->
|
||||
e |> Json.errorToString
|
||||
@@ -0,0 +1,32 @@
|
||||
module ManyDecks.Google exposing (..)
|
||||
|
||||
import Http
|
||||
import Json.Decode as Json
|
||||
import Json.Decode.Pipeline as Json
|
||||
import Json.Encode
|
||||
import ManyDecks.Auth as Auth exposing (Auth)
|
||||
|
||||
|
||||
authResult : Json.Decoder (Result String String)
|
||||
authResult =
|
||||
let
|
||||
codeOrError code =
|
||||
case code of
|
||||
Just c ->
|
||||
Json.succeed Ok
|
||||
|> Json.required "code" Json.string
|
||||
|
||||
Nothing ->
|
||||
Json.succeed Err
|
||||
|> Json.required "error" Json.string
|
||||
in
|
||||
Json.maybe (Json.field "code" Json.string) |> Json.andThen codeOrError
|
||||
|
||||
|
||||
signIn : String -> (Result Http.Error Auth -> msg) -> Cmd msg
|
||||
signIn code toMsg =
|
||||
Http.post
|
||||
{ url = "/api/users"
|
||||
, body = [ ( "google", code |> Json.Encode.string ) ] |> Json.Encode.object |> Http.jsonBody
|
||||
, expect = Http.expectJson toMsg Auth.decoder
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
module ManyDecks.Messages exposing (Msg(..))
|
||||
|
||||
import Bytes exposing (Bytes)
|
||||
import Cards.Deck as Deck
|
||||
import File exposing (File)
|
||||
import Json.Patch.Invertible as Json
|
||||
import ManyDecks.Auth exposing (Auth)
|
||||
import ManyDecks.Error exposing (Error)
|
||||
import ManyDecks.Pages.Decks.Deck as Deck
|
||||
import ManyDecks.Pages.Decks.Model as Decks
|
||||
import ManyDecks.Pages.Edit.Model as Edit exposing (Change)
|
||||
import ManyDecks.Pages.Profile.Model as Profile
|
||||
|
||||
|
||||
type Msg
|
||||
= NoOp
|
||||
| SetError Error
|
||||
| TryGoogleAuth
|
||||
| GoogleAuthResult String
|
||||
| MdAuthResult Auth
|
||||
| ReceiveDecks (List Decks.CodeAndSummary)
|
||||
| UploadDeck
|
||||
| UploadedDeck File
|
||||
| Json5Parse String
|
||||
| NewDeck Deck.Deck
|
||||
| EditDeck Deck.Code (Maybe Deck.Deck) Bool
|
||||
| BackFromEdit
|
||||
| Copy String
|
||||
| ProfileMsg Profile.Msg
|
||||
| EditMsg Edit.Msg
|
||||
| Backup
|
||||
| DownloadBytes Bytes
|
||||
| UpdateAuth Auth
|
||||
| Delete Deck.Code
|
||||
| Save Deck.Code Json.Patch
|
||||
| SignOut
|
||||
| Error String
|
||||
@@ -0,0 +1,164 @@
|
||||
module ManyDecks.Pages.Decks exposing (..)
|
||||
|
||||
import Bytes exposing (Bytes)
|
||||
import Cards.Deck as Deck exposing (Deck)
|
||||
import FontAwesome.Attributes as Icon
|
||||
import FontAwesome.Icon as Icon
|
||||
import FontAwesome.Solid as Icon
|
||||
import Html exposing (Html)
|
||||
import Html.Attributes as HtmlA
|
||||
import Html.Events as HtmlE
|
||||
import Html.Keyed as HtmlK
|
||||
import Http
|
||||
import Json.Decode as Json
|
||||
import Json.Encode
|
||||
import Json.Patch
|
||||
import Json.Patch.Invertible as Json
|
||||
import ManyDecks.Messages exposing (Msg(..))
|
||||
import ManyDecks.Pages.Decks.Deck as Deck exposing (codeDecoder)
|
||||
import ManyDecks.Pages.Decks.Model exposing (..)
|
||||
import Material.Button as Button
|
||||
import Material.Card as Card
|
||||
|
||||
|
||||
view : Maybe (List CodeAndSummary) -> List (Html Msg)
|
||||
view decks =
|
||||
let
|
||||
renderedDecks =
|
||||
case decks of
|
||||
Just d ->
|
||||
d |> List.map deck |> HtmlK.ul []
|
||||
|
||||
Nothing ->
|
||||
Icon.spinner |> Icon.viewStyled [ Icon.spin ]
|
||||
|
||||
newDeck =
|
||||
Button.view Button.Raised
|
||||
Button.Padded
|
||||
"New Deck"
|
||||
(Icon.plus |> Icon.viewIcon |> Just)
|
||||
(Deck.empty |> NewDeck |> Just)
|
||||
|
||||
uploadDeck =
|
||||
Button.view Button.Raised
|
||||
Button.Padded
|
||||
"Upload Deck"
|
||||
(Icon.upload |> Icon.viewIcon |> Just)
|
||||
(Just UploadDeck)
|
||||
|
||||
controls =
|
||||
Html.div [ HtmlA.class "controls" ] [ uploadDeck, newDeck ]
|
||||
in
|
||||
[ Card.view [ HtmlA.class "decks" ] [ renderedDecks, controls ] ]
|
||||
|
||||
|
||||
deck : CodeAndSummary -> ( String, Html Msg )
|
||||
deck { code, summary } =
|
||||
( code |> Deck.codeToString
|
||||
, Html.li [ HtmlA.class "deck" ]
|
||||
[ Deck.viewCode Copy code
|
||||
, Html.div [ HtmlA.class "details", EditDeck code Nothing False |> HtmlE.onClick ]
|
||||
[ Html.span [ HtmlA.class "name", HtmlA.title summary.details.name ] [ Html.text summary.details.name ]
|
||||
, Html.span [ HtmlA.class "language" ] [ summary.details.language |> Maybe.withDefault "" |> Html.text ]
|
||||
]
|
||||
, Html.div [ HtmlA.class "cards" ]
|
||||
[ Html.span [ HtmlA.class "calls", HtmlA.title "Calls" ]
|
||||
[ summary.calls |> String.fromInt |> Html.text ]
|
||||
, Html.span [ HtmlA.class "responses", HtmlA.title "Responses" ]
|
||||
[ summary.responses |> String.fromInt |> Html.text ]
|
||||
]
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
getDeck : Deck.Code -> (Result Http.Error Deck -> msg) -> Cmd msg
|
||||
getDeck code toMsg =
|
||||
Http.get
|
||||
{ url = "/api/decks/" ++ (code |> Deck.codeToString)
|
||||
, expect = Http.expectJson toMsg Deck.decode
|
||||
}
|
||||
|
||||
|
||||
getDecks : String -> (Result Http.Error (List CodeAndSummary) -> msg) -> Cmd msg
|
||||
getDecks token toMsg =
|
||||
Http.post
|
||||
{ url = "/api/decks"
|
||||
, body = [ ( "token", token |> Json.Encode.string ) ] |> Json.Encode.object |> Http.jsonBody
|
||||
, expect = Http.expectJson toMsg (summaryAndCodeDecoder |> Json.list)
|
||||
}
|
||||
|
||||
|
||||
createDeck : String -> Deck.Deck -> (Result Http.Error Deck.Code -> msg) -> Cmd msg
|
||||
createDeck token d toMsg =
|
||||
Http.post
|
||||
{ url = "/api/decks"
|
||||
, body =
|
||||
[ ( "token", token |> Json.Encode.string )
|
||||
, ( "initial", d |> Deck.encode )
|
||||
]
|
||||
|> Json.Encode.object
|
||||
|> Http.jsonBody
|
||||
, expect = Http.expectJson toMsg codeDecoder
|
||||
}
|
||||
|
||||
|
||||
deleteDeck : String -> Deck.Code -> Cmd Msg
|
||||
deleteDeck token code =
|
||||
Http.request
|
||||
{ method = "DELETE"
|
||||
, headers = []
|
||||
, url = "/api/decks/" ++ Deck.codeToString code
|
||||
, body = [ ( "token", token |> Json.Encode.string ) ] |> Json.Encode.object |> Http.jsonBody
|
||||
, expect = Http.expectWhatever (always NoOp)
|
||||
, timeout = Nothing
|
||||
, tracker = Nothing
|
||||
}
|
||||
|
||||
|
||||
save : String -> Deck.Code -> Json.Patch -> (Result Http.Error () -> msg) -> Cmd msg
|
||||
save token code patch toMsg =
|
||||
Http.request
|
||||
{ method = "PATCH"
|
||||
, headers = []
|
||||
, url = "/api/decks/" ++ Deck.codeToString code
|
||||
, body =
|
||||
[ ( "token", token |> Json.Encode.string )
|
||||
, ( "patch", patch |> Json.toPatch |> Json.Patch.encoder )
|
||||
]
|
||||
|> Json.Encode.object
|
||||
|> Http.jsonBody
|
||||
, expect = Http.expectWhatever toMsg
|
||||
, timeout = Nothing
|
||||
, tracker = Nothing
|
||||
}
|
||||
|
||||
|
||||
backup : String -> (Result Http.Error Bytes -> msg) -> Cmd msg
|
||||
backup token toMsg =
|
||||
Http.post
|
||||
{ url = "/api/backup"
|
||||
, body =
|
||||
[ ( "token", token |> Json.Encode.string ) ]
|
||||
|> Json.Encode.object
|
||||
|> Http.jsonBody
|
||||
, expect = Http.expectBytesResponse toMsg resolve
|
||||
}
|
||||
|
||||
|
||||
resolve : Http.Response Bytes -> Result Http.Error Bytes
|
||||
resolve response =
|
||||
case response of
|
||||
Http.BadUrl_ url ->
|
||||
Err (Http.BadUrl url)
|
||||
|
||||
Http.Timeout_ ->
|
||||
Err Http.Timeout
|
||||
|
||||
Http.NetworkError_ ->
|
||||
Err Http.NetworkError
|
||||
|
||||
Http.BadStatus_ metadata _ ->
|
||||
Err (Http.BadStatus metadata.statusCode)
|
||||
|
||||
Http.GoodStatus_ _ body ->
|
||||
Ok body
|
||||
@@ -0,0 +1,190 @@
|
||||
module ManyDecks.Pages.Decks.Deck exposing
|
||||
( Call
|
||||
, Code
|
||||
, Details
|
||||
, EditableDeck
|
||||
, Line
|
||||
, Part(..)
|
||||
, Response
|
||||
, Style(..)
|
||||
, Summary
|
||||
, Transform(..)
|
||||
, codeDecoder
|
||||
, codeToString
|
||||
, detailsDecoder
|
||||
, editableDeckEncoder
|
||||
, summaryDecoder
|
||||
, viewCode
|
||||
)
|
||||
|
||||
import Html exposing (Html)
|
||||
import Html.Attributes as HtmlA
|
||||
import Html.Events as HtmlE
|
||||
import Json.Decode as Json
|
||||
import Json.Decode.Pipeline as Json
|
||||
import Json.Encode
|
||||
|
||||
|
||||
type Code
|
||||
= Code String
|
||||
|
||||
|
||||
codeDecoder : Json.Decoder Code
|
||||
codeDecoder =
|
||||
Json.string |> Json.map Code
|
||||
|
||||
|
||||
viewCode : (String -> msg) -> Code -> Html msg
|
||||
viewCode copy (Code code) =
|
||||
Html.input
|
||||
[ code |> HtmlA.id
|
||||
, HtmlA.type_ "text"
|
||||
, HtmlA.readonly True
|
||||
, HtmlA.class "deck-code"
|
||||
, HtmlA.value code
|
||||
, code |> copy |> HtmlE.onClick
|
||||
]
|
||||
[]
|
||||
|
||||
|
||||
codeToString : Code -> String
|
||||
codeToString (Code code) =
|
||||
code
|
||||
|
||||
|
||||
type Transform
|
||||
= NoTransform
|
||||
| UpperCase
|
||||
| Capitalize
|
||||
|
||||
|
||||
type Style
|
||||
= NoStyle
|
||||
| Em
|
||||
|
||||
|
||||
type Part
|
||||
= Text String Style
|
||||
| Slot Transform Style
|
||||
|
||||
|
||||
type alias Line =
|
||||
List Part
|
||||
|
||||
|
||||
type alias Call =
|
||||
List Line
|
||||
|
||||
|
||||
type alias Response =
|
||||
String
|
||||
|
||||
|
||||
type alias Details =
|
||||
{ name : String
|
||||
, author : String
|
||||
, language : Maybe String
|
||||
}
|
||||
|
||||
|
||||
detailsDecoder : Json.Decoder Details
|
||||
detailsDecoder =
|
||||
Json.succeed Details
|
||||
|> Json.required "name" Json.string
|
||||
|> Json.required "author" Json.string
|
||||
|> Json.optional "language" (Json.string |> Json.map Just) Nothing
|
||||
|
||||
|
||||
type alias Summary =
|
||||
{ details : Details
|
||||
, calls : Int
|
||||
, responses : Int
|
||||
, version : Int
|
||||
}
|
||||
|
||||
|
||||
summaryDecoder : Json.Decoder Summary
|
||||
summaryDecoder =
|
||||
Json.succeed Summary
|
||||
|> Json.required "details" detailsDecoder
|
||||
|> Json.required "calls" Json.int
|
||||
|> Json.required "responses" Json.int
|
||||
|> Json.required "version" Json.int
|
||||
|
||||
|
||||
type alias Deck =
|
||||
{ details : Details
|
||||
, calls : List Call
|
||||
, responses : List Response
|
||||
, version : Int
|
||||
}
|
||||
|
||||
|
||||
type alias EditableDeck =
|
||||
{ name : String
|
||||
, language : String
|
||||
, calls : List Call
|
||||
, responses : List Response
|
||||
}
|
||||
|
||||
|
||||
editableDeckEncoder : EditableDeck -> Json.Value
|
||||
editableDeckEncoder { name, language, calls, responses } =
|
||||
Json.Encode.object
|
||||
[ ( "name", name |> Json.Encode.string )
|
||||
, ( "language", language |> Json.Encode.string )
|
||||
, ( "calls", calls |> Json.Encode.list encodeCall )
|
||||
, ( "responses", responses |> Json.Encode.list Json.Encode.string )
|
||||
]
|
||||
|
||||
|
||||
encodeCall : List (List Part) -> Json.Encode.Value
|
||||
encodeCall =
|
||||
Json.Encode.list encodeLine
|
||||
|
||||
|
||||
encodeLine : List Part -> Json.Encode.Value
|
||||
encodeLine =
|
||||
Json.Encode.list encodePart
|
||||
|
||||
|
||||
encodePart : Part -> Json.Encode.Value
|
||||
encodePart part =
|
||||
let
|
||||
fields =
|
||||
case part of
|
||||
Text text style ->
|
||||
[ text |> encodeText, style |> encodeStyle ]
|
||||
|
||||
Slot transform style ->
|
||||
[ transform |> encodeTransform, style |> encodeStyle ]
|
||||
in
|
||||
fields |> List.concat |> Json.Encode.object
|
||||
|
||||
|
||||
encodeText : String -> List ( String, Json.Encode.Value )
|
||||
encodeText text =
|
||||
[ ( "text", text |> Json.Encode.string ) ]
|
||||
|
||||
|
||||
encodeStyle : Style -> List ( String, Json.Encode.Value )
|
||||
encodeStyle style =
|
||||
case style of
|
||||
NoStyle ->
|
||||
[]
|
||||
|
||||
Em ->
|
||||
[ ( "style", "Em" |> Json.Encode.string ) ]
|
||||
|
||||
|
||||
encodeTransform : Transform -> List ( String, Json.Encode.Value )
|
||||
encodeTransform transform =
|
||||
case transform of
|
||||
NoTransform ->
|
||||
[]
|
||||
|
||||
Capitalize ->
|
||||
[ ( "transform", "Capitalize" |> Json.Encode.string ) ]
|
||||
|
||||
UpperCase ->
|
||||
[ ( "transform", "UpperCase" |> Json.Encode.string ) ]
|
||||
@@ -0,0 +1,18 @@
|
||||
module ManyDecks.Pages.Decks.Model exposing (..)
|
||||
|
||||
import Json.Decode as Json
|
||||
import Json.Decode.Pipeline as Json
|
||||
import ManyDecks.Pages.Decks.Deck as Deck
|
||||
|
||||
|
||||
type alias CodeAndSummary =
|
||||
{ code : Deck.Code
|
||||
, summary : Deck.Summary
|
||||
}
|
||||
|
||||
|
||||
summaryAndCodeDecoder : Json.Decoder CodeAndSummary
|
||||
summaryAndCodeDecoder =
|
||||
Json.succeed CodeAndSummary
|
||||
|> Json.required "code" Deck.codeDecoder
|
||||
|> Json.required "summary" Deck.summaryDecoder
|
||||
@@ -0,0 +1,488 @@
|
||||
module ManyDecks.Pages.Edit exposing
|
||||
( init
|
||||
, subscriptions
|
||||
, update
|
||||
, view
|
||||
)
|
||||
|
||||
import Cards.Call as Call exposing (Call(..))
|
||||
import Cards.Card as GameCard
|
||||
import Cards.Deck exposing (Deck)
|
||||
import Cards.Response as Response exposing (Response(..))
|
||||
import FontAwesome.Icon as Icon
|
||||
import FontAwesome.Regular as RegularIcon
|
||||
import FontAwesome.Solid as Icon
|
||||
import Html exposing (Html)
|
||||
import Html.Attributes as HtmlA
|
||||
import Html.Events as HtmlE
|
||||
import Json.Patch.Invertible as Json
|
||||
import List.Extra as List
|
||||
import ManyDecks.Pages.Decks.Deck as Deck
|
||||
import ManyDecks.Pages.Edit.CallEditor as CallEditor
|
||||
import ManyDecks.Pages.Edit.CallEditor.Model as CallEditor
|
||||
import ManyDecks.Pages.Edit.Change as Change
|
||||
import ManyDecks.Pages.Edit.Import as Import
|
||||
import ManyDecks.Pages.Edit.Import.Model as Import
|
||||
import ManyDecks.Pages.Edit.Model exposing (..)
|
||||
import Material.Button as Button
|
||||
import Material.Card as Card
|
||||
import Material.IconButton as IconButton
|
||||
import Material.Switch as Switch
|
||||
import Material.TextField as TextField
|
||||
|
||||
|
||||
init : Deck.Code -> Deck -> Model
|
||||
init code deck =
|
||||
{ code = code
|
||||
, deck = deck
|
||||
, editing = Nothing
|
||||
, changes = []
|
||||
, redoStack = []
|
||||
, errors = []
|
||||
, deletionEnabled = False
|
||||
, importer = Nothing
|
||||
}
|
||||
|
||||
|
||||
update : Msg -> Model -> ( Model, Cmd msg )
|
||||
update msg model =
|
||||
case msg of
|
||||
Edit u ->
|
||||
case u of
|
||||
UpdateName newName ->
|
||||
let
|
||||
editing =
|
||||
case model.editing of
|
||||
Just (NameEditor old _) ->
|
||||
NameEditor old newName |> Just
|
||||
|
||||
other ->
|
||||
other
|
||||
in
|
||||
( { model | editing = editing }, Cmd.none )
|
||||
|
||||
UpdateResponse newResponse ->
|
||||
let
|
||||
editing =
|
||||
case model.editing of
|
||||
Just (ResponseEditor index old _) ->
|
||||
ResponseEditor index old newResponse |> Just
|
||||
|
||||
other ->
|
||||
other
|
||||
in
|
||||
( { model | editing = editing }, Cmd.none )
|
||||
|
||||
UpdateCall callEditorMsg ->
|
||||
let
|
||||
editing =
|
||||
case model.editing of
|
||||
Just (CallEditor index old m) ->
|
||||
m |> CallEditor.update callEditorMsg |> CallEditor index old |> Just
|
||||
|
||||
other ->
|
||||
other
|
||||
in
|
||||
( { model | editing = editing }, Cmd.none )
|
||||
|
||||
StartEditing cardEditor ->
|
||||
let
|
||||
m =
|
||||
endEditing model
|
||||
in
|
||||
( { m | editing = Just cardEditor }, Cmd.none )
|
||||
|
||||
EndEditing ->
|
||||
( endEditing model, Cmd.none )
|
||||
|
||||
Delete ->
|
||||
case model.editing of
|
||||
Just (CallEditor index old _) ->
|
||||
( model |> applyChanges [ Remove index old |> CallChange ], Cmd.none )
|
||||
|
||||
Just (ResponseEditor index old _) ->
|
||||
( model |> applyChanges [ Remove index old |> ResponseChange ], Cmd.none )
|
||||
|
||||
_ ->
|
||||
( model, Cmd.none )
|
||||
|
||||
ApplyChange change ->
|
||||
( model |> applyChanges [ change ], Cmd.none )
|
||||
|
||||
Undo ->
|
||||
case model.changes |> List.unconsLast of
|
||||
Just ( last, rest ) ->
|
||||
case model.deck |> Change.undo [ last ] of
|
||||
Ok deck ->
|
||||
( { model | changes = rest, deck = deck, redoStack = last :: model.redoStack }, Cmd.none )
|
||||
|
||||
Err error ->
|
||||
( addChangeError [ last ] error True model, Cmd.none )
|
||||
|
||||
Nothing ->
|
||||
( model, Cmd.none )
|
||||
|
||||
Redo ->
|
||||
case model.redoStack of
|
||||
first :: rest ->
|
||||
case model.deck |> Change.apply [ first ] of
|
||||
Ok deck ->
|
||||
( { model | changes = model.changes ++ [ first ], deck = deck, redoStack = rest }, Cmd.none )
|
||||
|
||||
Err error ->
|
||||
( addChangeError [ first ] error False model, Cmd.none )
|
||||
|
||||
[] ->
|
||||
( model, Cmd.none )
|
||||
|
||||
SetDeletionEnabled enabled ->
|
||||
( { model | deletionEnabled = enabled }, Cmd.none )
|
||||
|
||||
SetImportVisible visible ->
|
||||
let
|
||||
importer =
|
||||
if visible then
|
||||
Just Import.init
|
||||
|
||||
else
|
||||
Nothing
|
||||
in
|
||||
( { model | importer = importer }, Cmd.none )
|
||||
|
||||
Import ->
|
||||
case model.importer of
|
||||
Just importer ->
|
||||
let
|
||||
cards =
|
||||
importer |> Import.importedCards
|
||||
|
||||
toChangeAndApply card m =
|
||||
let
|
||||
change =
|
||||
case card of
|
||||
Import.ImportedCall c ->
|
||||
Add (m.deck.calls |> List.length) c |> CallChange
|
||||
|
||||
Import.ImportedResponse r ->
|
||||
Add (m.deck.responses |> List.length) r |> ResponseChange
|
||||
in
|
||||
applyChanges [ change ] m
|
||||
|
||||
newModel =
|
||||
cards |> List.foldl toChangeAndApply model
|
||||
in
|
||||
( { newModel | importer = Nothing }, Cmd.none )
|
||||
|
||||
Nothing ->
|
||||
( model, Cmd.none )
|
||||
|
||||
UpdateImportText text ->
|
||||
case model.importer of
|
||||
Just importer ->
|
||||
( { model | importer = Just { importer | text = text } }, Cmd.none )
|
||||
|
||||
Nothing ->
|
||||
( model, Cmd.none )
|
||||
|
||||
|
||||
view : msg -> (Deck.Code -> Json.Patch -> msg) -> (Deck.Code -> msg) -> (Msg -> msg) -> Model -> List (Html msg)
|
||||
view back save delete wrap model =
|
||||
case model.importer of
|
||||
Just importer ->
|
||||
Import.view wrap importer
|
||||
|
||||
Nothing ->
|
||||
let
|
||||
viewResponse r =
|
||||
[ Response.view (UpdateResponse >> Edit >> wrap |> GameCard.Mutable) GameCard.Face r ]
|
||||
|
||||
editing editor =
|
||||
case editor of
|
||||
CallEditor _ _ editorModel ->
|
||||
inEditing [ CallEditor.view (UpdateCall >> Edit >> wrap) editorModel ] (Just editorModel) |> Just
|
||||
|
||||
ResponseEditor _ _ new ->
|
||||
inEditing (viewResponse new) Nothing |> Just
|
||||
|
||||
NameEditor _ _ ->
|
||||
Nothing
|
||||
|
||||
inEditing c callEditor =
|
||||
let
|
||||
d =
|
||||
IconButton.view (Icon.trash |> Icon.viewIcon) "Delete" (Delete |> wrap |> Just)
|
||||
|
||||
( problems, addSlot ) =
|
||||
case callEditor of
|
||||
Just editorModel ->
|
||||
( CallEditor.problems editorModel
|
||||
, IconButton.view (Icon.plusCircle |> Icon.viewIcon)
|
||||
"Add Slot"
|
||||
(CallEditor.AddSlot |> UpdateCall |> Edit |> wrap |> Just)
|
||||
|> Just
|
||||
)
|
||||
|
||||
_ ->
|
||||
( [], Nothing )
|
||||
|
||||
noProblems =
|
||||
List.isEmpty problems
|
||||
|
||||
sAction =
|
||||
if noProblems then
|
||||
EndEditing |> wrap |> Just
|
||||
|
||||
else
|
||||
Nothing
|
||||
|
||||
s =
|
||||
IconButton.view (Icon.save |> Icon.viewIcon) "Save" sAction
|
||||
|
||||
controlsContents =
|
||||
[ Just d, addSlot, Just s ] |> List.filterMap identity
|
||||
|
||||
problemsView =
|
||||
if noProblems then
|
||||
Html.text ""
|
||||
|
||||
else
|
||||
Html.ul [ HtmlA.class "problems" ]
|
||||
(problems |> List.map (\p -> Html.li [] [ Html.text p ]))
|
||||
in
|
||||
[ Html.div [ HtmlA.class "overlay" ]
|
||||
[ Html.div [ HtmlA.class "background", EndEditing |> wrap |> HtmlE.onClick ] []
|
||||
, Card.view []
|
||||
[ Html.div [ HtmlA.class "editing" ] c
|
||||
, problemsView
|
||||
, Html.div [ HtmlA.class "editing-controls" ] controlsContents
|
||||
]
|
||||
]
|
||||
]
|
||||
|
||||
undoAction =
|
||||
if List.isEmpty model.changes then
|
||||
Nothing
|
||||
|
||||
else
|
||||
Undo |> wrap |> Just
|
||||
|
||||
redoAction =
|
||||
if List.isEmpty model.redoStack then
|
||||
Nothing
|
||||
|
||||
else
|
||||
Redo |> wrap |> Just
|
||||
|
||||
saveAction =
|
||||
if List.isEmpty model.changes then
|
||||
Nothing
|
||||
|
||||
else
|
||||
save model.code (model.changes |> Change.toPatch) |> Just
|
||||
|
||||
actions =
|
||||
Html.div [ HtmlA.class "actions" ]
|
||||
[ Button.view
|
||||
Button.Standard
|
||||
Button.Padded
|
||||
"Back"
|
||||
(Icon.arrowLeft |> Icon.viewIcon |> Just)
|
||||
(back |> Just)
|
||||
, Button.view
|
||||
Button.Standard
|
||||
Button.Padded
|
||||
"Import"
|
||||
(Icon.fileImport |> Icon.viewIcon |> Just)
|
||||
(True |> SetImportVisible |> wrap |> Just)
|
||||
, Button.view
|
||||
Button.Standard
|
||||
Button.Padded
|
||||
"Undo"
|
||||
(Icon.undo |> Icon.viewIcon |> Just)
|
||||
undoAction
|
||||
, Button.view
|
||||
Button.Standard
|
||||
Button.Padded
|
||||
"Redo"
|
||||
(Icon.redo |> Icon.viewIcon |> Just)
|
||||
redoAction
|
||||
, Button.view
|
||||
Button.Standard
|
||||
Button.Padded
|
||||
"Save"
|
||||
(Icon.save |> Icon.viewIcon |> Just)
|
||||
saveAction
|
||||
]
|
||||
|
||||
errorView =
|
||||
if model.errors |> List.isEmpty then
|
||||
[]
|
||||
|
||||
else
|
||||
[ Html.div [ HtmlA.class "overlay" ]
|
||||
[ Html.div [ HtmlA.class "background" ] []
|
||||
, Card.view [ HtmlA.class "errors" ]
|
||||
[ Html.ul [] (model.errors |> List.map (viewError model.deck)) ]
|
||||
]
|
||||
]
|
||||
|
||||
deleteAction =
|
||||
if model.deletionEnabled then
|
||||
model.code |> delete |> Just
|
||||
|
||||
else
|
||||
Nothing
|
||||
in
|
||||
List.concat
|
||||
[ [ Card.view [ HtmlA.class "edit" ]
|
||||
[ actions
|
||||
, details wrap (model |> editingName |> Maybe.withDefault model.deck.name)
|
||||
, Html.div [ HtmlA.class "cards" ]
|
||||
[ calls wrap model.deck.calls
|
||||
, responses wrap model.deck.responses
|
||||
]
|
||||
, Html.div [ HtmlA.class "delete" ]
|
||||
[ Switch.view
|
||||
(Html.span []
|
||||
[ Html.text "I am sure I want to "
|
||||
, Html.strong [] [ Html.text "permanently" ]
|
||||
, Html.text " delete this deck."
|
||||
]
|
||||
)
|
||||
model.deletionEnabled
|
||||
(SetDeletionEnabled >> wrap |> Just)
|
||||
, Button.view
|
||||
Button.Raised
|
||||
Button.Padded
|
||||
"Delete"
|
||||
(Icon.trash |> Icon.viewIcon |> Just)
|
||||
deleteAction
|
||||
]
|
||||
]
|
||||
]
|
||||
, model.editing |> Maybe.andThen editing |> Maybe.withDefault []
|
||||
, errorView
|
||||
]
|
||||
|
||||
|
||||
subscriptions : (Msg -> msg) -> Model -> Sub msg
|
||||
subscriptions wrap model =
|
||||
case model.editing of
|
||||
Just (CallEditor _ _ _) ->
|
||||
CallEditor.subscriptions (UpdateCall >> Edit >> wrap)
|
||||
|
||||
_ ->
|
||||
Sub.none
|
||||
|
||||
|
||||
viewError : Deck -> EditError -> Html msg
|
||||
viewError deck error =
|
||||
let
|
||||
content =
|
||||
case error of
|
||||
ChangeError e changes undoing ->
|
||||
[ Change.asContextForError e changes undoing ]
|
||||
in
|
||||
Html.li [ HtmlA.class "error" ] content
|
||||
|
||||
|
||||
editingName : Model -> Maybe String
|
||||
editingName model =
|
||||
case model.editing of
|
||||
Just (NameEditor _ new) ->
|
||||
Just new
|
||||
|
||||
_ ->
|
||||
Nothing
|
||||
|
||||
|
||||
details : (Msg -> msg) -> String -> Html msg
|
||||
details wrap name =
|
||||
Html.div [ HtmlA.class "details" ]
|
||||
[ TextField.viewWithFocus "Title"
|
||||
TextField.Text
|
||||
name
|
||||
(UpdateName >> Edit >> wrap |> Just)
|
||||
(NameEditor name name |> StartEditing |> wrap)
|
||||
(EndEditing |> wrap)
|
||||
]
|
||||
|
||||
|
||||
calls : (Msg -> msg) -> List Call -> Html msg
|
||||
calls wrap cs =
|
||||
let
|
||||
add =
|
||||
Button.view
|
||||
Button.Standard
|
||||
Button.Padded
|
||||
"New Call"
|
||||
(Icon.square |> Icon.viewIcon |> Just)
|
||||
(Add (cs |> List.length) Call.init |> CallChange |> ApplyChange |> wrap |> Just)
|
||||
|
||||
content =
|
||||
(cs |> List.indexedMap (call wrap)) ++ [ Html.li [ HtmlA.class "add" ] [ add ] ]
|
||||
in
|
||||
Html.ul [ HtmlA.class "calls" ] content
|
||||
|
||||
|
||||
call : (Msg -> msg) -> Int -> Call -> Html msg
|
||||
call wrap index c =
|
||||
Html.li [ CallEditor index c (Call.editor c) |> StartEditing |> wrap |> HtmlE.onClick ]
|
||||
[ c |> Call.toString "⏎" [] |> Html.text ]
|
||||
|
||||
|
||||
responses : (Msg -> msg) -> List Response -> Html msg
|
||||
responses wrap rs =
|
||||
let
|
||||
add =
|
||||
Button.view
|
||||
Button.Standard
|
||||
Button.Padded
|
||||
"New Response"
|
||||
(RegularIcon.square |> Icon.viewIcon |> Just)
|
||||
(Add (rs |> List.length) Response.init |> ResponseChange |> ApplyChange |> wrap |> Just)
|
||||
|
||||
content =
|
||||
(rs |> List.indexedMap (response wrap)) ++ [ Html.li [ HtmlA.class "add" ] [ add ] ]
|
||||
in
|
||||
Html.ul [ HtmlA.class "responses" ] content
|
||||
|
||||
|
||||
response : (Msg -> msg) -> Int -> Response -> Html msg
|
||||
response wrap index r =
|
||||
Html.li [ ResponseEditor index r r |> StartEditing |> wrap |> HtmlE.onClick ]
|
||||
[ r |> Response.toString |> Html.text ]
|
||||
|
||||
|
||||
endEditing : Model -> Model
|
||||
endEditing model =
|
||||
case model.editing of
|
||||
Just finished ->
|
||||
let
|
||||
changes =
|
||||
finished |> Change.fromEditor
|
||||
in
|
||||
case changes of
|
||||
Ok cs ->
|
||||
applyChanges cs model
|
||||
|
||||
Err _ ->
|
||||
model
|
||||
|
||||
Nothing ->
|
||||
model
|
||||
|
||||
|
||||
applyChanges : List Change -> Model -> Model
|
||||
applyChanges changes model =
|
||||
case model.deck |> Change.apply changes of
|
||||
Ok deck ->
|
||||
{ model | changes = model.changes ++ changes, deck = deck, editing = Nothing, redoStack = [] }
|
||||
|
||||
Err error ->
|
||||
addChangeError changes error False model
|
||||
|
||||
|
||||
addChangeError : List Change -> String -> Bool -> Model -> Model
|
||||
addChangeError changes error undo model =
|
||||
{ model | errors = ChangeError error changes undo :: model.errors }
|
||||
@@ -0,0 +1,409 @@
|
||||
module ManyDecks.Pages.Edit.CallEditor exposing
|
||||
( problems
|
||||
, subscriptions
|
||||
, update
|
||||
, view
|
||||
)
|
||||
|
||||
import Browser.Events as Browser
|
||||
import Cards.Call as Call
|
||||
import Cards.Call.Style as Style
|
||||
import Cards.Call.Transform as Transform
|
||||
import Cards.Card as Card
|
||||
import Html exposing (Html)
|
||||
import Html.Attributes as HtmlA
|
||||
import Html.Events as HtmlE
|
||||
import Json.Decode as Json
|
||||
import List.Extra as List
|
||||
import ManyDecks.Pages.Edit.CallEditor.Model exposing (..)
|
||||
|
||||
|
||||
deleteSpan : Span -> Model -> Model
|
||||
deleteSpan { start, end } model =
|
||||
let
|
||||
left =
|
||||
model.atoms |> List.take start
|
||||
|
||||
right =
|
||||
model.atoms |> List.drop end
|
||||
in
|
||||
{ model | atoms = List.concat [ left, right ], selection = Nothing, cursor = start }
|
||||
|
||||
|
||||
insertAt : List Atom -> Position -> Model -> Model
|
||||
insertAt new position model =
|
||||
let
|
||||
( left, right ) =
|
||||
model.atoms |> List.splitAt position
|
||||
|
||||
atoms =
|
||||
List.concat [ left, new, right ]
|
||||
in
|
||||
{ model | atoms = atoms, cursor = position + List.length new }
|
||||
|
||||
|
||||
moveCursor : (Position -> Position) -> Model -> Model
|
||||
moveCursor move model =
|
||||
let
|
||||
afterLast =
|
||||
List.length model.atoms
|
||||
|
||||
cursor =
|
||||
min afterLast (max (model.cursor |> move) 0)
|
||||
|
||||
selection =
|
||||
case model.selecting of
|
||||
Just start ->
|
||||
selectionOf start cursor
|
||||
|
||||
Nothing ->
|
||||
Nothing
|
||||
in
|
||||
{ model | cursor = cursor, selection = selection }
|
||||
|
||||
|
||||
moveRow : Int -> Model -> Model
|
||||
moveRow diff model =
|
||||
let
|
||||
applyNTimes n f value =
|
||||
if n > 0 then
|
||||
value |> f |> applyNTimes (n - 1) f
|
||||
|
||||
else
|
||||
value
|
||||
|
||||
atoms =
|
||||
model.atoms
|
||||
in
|
||||
if diff > 0 then
|
||||
model |> applyNTimes diff (moveCursor (\p -> p + toEndOfLine atoms p + 1))
|
||||
|
||||
else
|
||||
model |> applyNTimes -diff (moveCursor (\p -> p - toStartOfLine atoms p - 1))
|
||||
|
||||
|
||||
toEndOfLine : List Atom -> Position -> Int
|
||||
toEndOfLine atoms p =
|
||||
atoms
|
||||
|> List.drop p
|
||||
|> List.findIndex ((==) NewLine)
|
||||
|> Maybe.withDefault (List.length atoms)
|
||||
|
||||
|
||||
toStartOfLine : List Atom -> Position -> Int
|
||||
toStartOfLine atoms p =
|
||||
let
|
||||
pRev =
|
||||
List.length atoms - p
|
||||
in
|
||||
atoms
|
||||
|> List.reverse
|
||||
|> List.drop pRev
|
||||
|> List.findIndex ((==) NewLine)
|
||||
|> Maybe.withDefault p
|
||||
|
||||
|
||||
update : Msg -> Model -> Model
|
||||
update msg model =
|
||||
case msg of
|
||||
KeyUp key ->
|
||||
case key of
|
||||
Control "Shift" ->
|
||||
{ model | selecting = Nothing }
|
||||
|
||||
Control "Control" ->
|
||||
{ model | control = False }
|
||||
|
||||
_ ->
|
||||
model
|
||||
|
||||
KeyDown key ->
|
||||
let
|
||||
cursor =
|
||||
model.cursor
|
||||
|
||||
op =
|
||||
case key of
|
||||
Control "Delete" ->
|
||||
case model.selection of
|
||||
Nothing ->
|
||||
deleteSpan (span cursor (cursor + 1))
|
||||
|
||||
Just selection ->
|
||||
deleteSpan selection
|
||||
|
||||
Control "Backspace" ->
|
||||
case model.selection of
|
||||
Nothing ->
|
||||
deleteSpan (span (cursor - 1) cursor)
|
||||
|
||||
Just selection ->
|
||||
deleteSpan selection
|
||||
|
||||
Control "Enter" ->
|
||||
case model.selection of
|
||||
Nothing ->
|
||||
insertAt [ NewLine ] cursor
|
||||
|
||||
Just selection ->
|
||||
deleteSpan selection >> (\m -> insertAt [ NewLine ] m.cursor m)
|
||||
|
||||
Control "ArrowLeft" ->
|
||||
moveCursor (\c -> c - 1)
|
||||
|
||||
Control "ArrowRight" ->
|
||||
moveCursor (\c -> c + 1)
|
||||
|
||||
Control "ArrowUp" ->
|
||||
moveRow -1
|
||||
|
||||
Control "ArrowDown" ->
|
||||
moveRow 1
|
||||
|
||||
Control "End" ->
|
||||
moveCursor (\p -> p + toEndOfLine model.atoms p)
|
||||
|
||||
Control "Home" ->
|
||||
moveCursor (\p -> p - toStartOfLine model.atoms p)
|
||||
|
||||
Control "Shift" ->
|
||||
\m -> { m | selecting = Just m.cursor }
|
||||
|
||||
Control "Control" ->
|
||||
\m -> { m | control = True }
|
||||
|
||||
Character char ->
|
||||
if model.control then
|
||||
identity
|
||||
|
||||
else
|
||||
case model.selection of
|
||||
Nothing ->
|
||||
insertAt [ Letter char ] cursor
|
||||
|
||||
Just selection ->
|
||||
deleteSpan selection >> insertAt [ Letter char ] selection.start
|
||||
|
||||
_ ->
|
||||
identity
|
||||
in
|
||||
op model
|
||||
|
||||
Enter position ->
|
||||
let
|
||||
( selection, cursor ) =
|
||||
case model.selecting of
|
||||
Just start ->
|
||||
let
|
||||
end =
|
||||
if position <= start then
|
||||
position
|
||||
|
||||
else
|
||||
position + 1
|
||||
in
|
||||
( selectionOf start end, end )
|
||||
|
||||
Nothing ->
|
||||
let
|
||||
c =
|
||||
if model.moving /= Nothing then
|
||||
position
|
||||
|
||||
else
|
||||
model.cursor
|
||||
in
|
||||
( model.selection, c )
|
||||
in
|
||||
{ model | hover = Just position, selection = selection, cursor = cursor }
|
||||
|
||||
Leave position ->
|
||||
let
|
||||
hover =
|
||||
if model.hover == Just position then
|
||||
Nothing
|
||||
|
||||
else
|
||||
model.hover
|
||||
in
|
||||
{ model | hover = hover }
|
||||
|
||||
StartSelection position ->
|
||||
{ model
|
||||
| selection = Nothing
|
||||
, selecting = Just position
|
||||
, cursor = position
|
||||
}
|
||||
|
||||
StartMoving position ->
|
||||
{ model | moving = Just position }
|
||||
|
||||
EndSelection position ->
|
||||
let
|
||||
( s, cursor ) =
|
||||
case model.selecting of
|
||||
Just start ->
|
||||
let
|
||||
end =
|
||||
if position <= start then
|
||||
position
|
||||
|
||||
else
|
||||
position + 1
|
||||
in
|
||||
( selectionOf start end, end )
|
||||
|
||||
Nothing ->
|
||||
( Nothing, position )
|
||||
|
||||
m =
|
||||
{ model | selection = s, selecting = Nothing, cursor = cursor }
|
||||
|
||||
newModel =
|
||||
case m.moving of
|
||||
Just from ->
|
||||
if from == position then
|
||||
{ m | selection = span from (from + 1) |> Just }
|
||||
|
||||
else
|
||||
let
|
||||
value =
|
||||
m.atoms
|
||||
|> List.getAt from
|
||||
|> Maybe.map (\v -> [ v ])
|
||||
|> Maybe.withDefault []
|
||||
|
||||
original =
|
||||
if position < from then
|
||||
from + 1
|
||||
|
||||
else
|
||||
from
|
||||
in
|
||||
m
|
||||
|> insertAt value position
|
||||
|> deleteSpan (span original (original + 1))
|
||||
|
||||
Nothing ->
|
||||
m
|
||||
in
|
||||
{ newModel | moving = Nothing }
|
||||
|
||||
AddSlot ->
|
||||
model |> insertAt [ Slot Transform.None Style.None ] model.cursor
|
||||
|
||||
|
||||
subscriptions : (Msg -> msg) -> Sub msg
|
||||
subscriptions wrap =
|
||||
Sub.batch
|
||||
[ Browser.onKeyDown (keyDecoder |> Json.map (KeyDown >> wrap))
|
||||
, Browser.onKeyUp (keyDecoder |> Json.map (KeyUp >> wrap))
|
||||
]
|
||||
|
||||
|
||||
lines : List Atom -> List (List ( Int, Atom ))
|
||||
lines =
|
||||
List.indexedMap (\i a -> ( i, a ))
|
||||
>> List.groupWhile (\( _, a ) _ -> a /= NewLine)
|
||||
>> List.map (\( f, r ) -> f :: r)
|
||||
|
||||
|
||||
view : (Msg -> msg) -> Model -> Html msg
|
||||
view wrap model =
|
||||
let
|
||||
content =
|
||||
model.atoms ++ [ NewLine ] |> lines |> List.map (viewLine wrap model)
|
||||
in
|
||||
Html.div [] [ Card.view Call.type_ Card.Immutable content Card.Face ]
|
||||
|
||||
|
||||
problems : Model -> List String
|
||||
problems model =
|
||||
if model.atoms |> List.any isSlot then
|
||||
[]
|
||||
|
||||
else
|
||||
[ "Calls must contain at least one slot." ]
|
||||
|
||||
|
||||
selectionOf : Position -> Position -> Maybe Span
|
||||
selectionOf start end =
|
||||
if start /= end then
|
||||
span start end |> Just
|
||||
|
||||
else
|
||||
Nothing
|
||||
|
||||
|
||||
viewLine : (Msg -> msg) -> Model -> List ( Int, Atom ) -> Html msg
|
||||
viewLine wrap model line =
|
||||
Html.p [] (line |> List.map (viewAtom wrap model))
|
||||
|
||||
|
||||
viewAtom : (Msg -> msg) -> Model -> ( Int, Atom ) -> Html msg
|
||||
viewAtom wrap model ( position, atom ) =
|
||||
let
|
||||
attrs =
|
||||
[ position |> Enter |> wrap |> HtmlE.onMouseEnter
|
||||
, position |> Leave |> wrap |> HtmlE.onMouseLeave
|
||||
, position |> EndSelection |> wrap |> HtmlE.onMouseUp
|
||||
, HtmlA.classList
|
||||
[ ( "cursor", model.cursor == position )
|
||||
, ( "selected", model.selection |> Maybe.map (inSpan position) |> Maybe.withDefault False )
|
||||
]
|
||||
]
|
||||
in
|
||||
case atom of
|
||||
Letter char ->
|
||||
Html.span
|
||||
([ position |> StartSelection |> wrap |> HtmlE.onMouseDown ] ++ attrs)
|
||||
[ char |> String.fromChar |> Html.text ]
|
||||
|
||||
Slot _ _ ->
|
||||
let
|
||||
slotAttrs =
|
||||
[ HtmlA.class "slot empty", position |> StartMoving |> wrap |> HtmlE.onMouseDown ]
|
||||
in
|
||||
Html.span (slotAttrs ++ attrs) []
|
||||
|
||||
NewLine ->
|
||||
Html.span ([ HtmlA.class "spacer" ] ++ attrs) []
|
||||
|
||||
|
||||
span : Position -> Position -> Span
|
||||
span a b =
|
||||
if a < b then
|
||||
Span a b
|
||||
|
||||
else
|
||||
Span b a
|
||||
|
||||
|
||||
inSpan : Position -> Span -> Bool
|
||||
inSpan position { start, end } =
|
||||
position >= start && position < end
|
||||
|
||||
|
||||
keyDecoder : Json.Decoder Key
|
||||
keyDecoder =
|
||||
Json.map toKey (Json.field "key" Json.string)
|
||||
|
||||
|
||||
toKey : String -> Key
|
||||
toKey string =
|
||||
case String.uncons string of
|
||||
Just ( char, "" ) ->
|
||||
Character char
|
||||
|
||||
_ ->
|
||||
Control string
|
||||
|
||||
|
||||
isSlot : Atom -> Bool
|
||||
isSlot atom =
|
||||
case atom of
|
||||
Slot _ _ ->
|
||||
True
|
||||
|
||||
_ ->
|
||||
False
|
||||
@@ -0,0 +1,48 @@
|
||||
module ManyDecks.Pages.Edit.CallEditor.Model exposing (..)
|
||||
|
||||
import Cards.Call.Style exposing (Style)
|
||||
import Cards.Call.Transform exposing (Transform)
|
||||
|
||||
|
||||
type alias Model =
|
||||
{ atoms : List Atom
|
||||
, selection : Maybe Span
|
||||
, selecting : Maybe Position
|
||||
, moving : Maybe Position
|
||||
, hover : Maybe Position
|
||||
, cursor : Position
|
||||
, styled : List ( Span, Style )
|
||||
, control : Bool
|
||||
}
|
||||
|
||||
|
||||
type alias Position =
|
||||
Int
|
||||
|
||||
|
||||
type alias Span =
|
||||
{ start : Position
|
||||
, end : Position
|
||||
}
|
||||
|
||||
|
||||
type Atom
|
||||
= Letter Char
|
||||
| Slot Transform Style
|
||||
| NewLine
|
||||
|
||||
|
||||
type Msg
|
||||
= Enter Position
|
||||
| Leave Position
|
||||
| StartSelection Position
|
||||
| EndSelection Position
|
||||
| StartMoving Position
|
||||
| KeyDown Key
|
||||
| KeyUp Key
|
||||
| AddSlot
|
||||
|
||||
|
||||
type Key
|
||||
= Character Char
|
||||
| Control String
|
||||
@@ -0,0 +1,109 @@
|
||||
module ManyDecks.Pages.Edit.Change exposing
|
||||
( apply
|
||||
, asContextForError
|
||||
, fromEditor
|
||||
, toPatch
|
||||
, undo
|
||||
)
|
||||
|
||||
import Cards.Call as Call
|
||||
import Cards.Deck as Deck exposing (Deck)
|
||||
import Cards.Response as Response
|
||||
import Html exposing (Html)
|
||||
import Html.Attributes as HtmlA
|
||||
import Json.Decode
|
||||
import Json.Encode as Json
|
||||
import Json.Patch
|
||||
import Json.Patch.Invertible as Json
|
||||
import Json.Pointer as Json
|
||||
import ManyDecks.Pages.Edit.Model exposing (..)
|
||||
|
||||
|
||||
apply : List Change -> Deck -> Result String Deck
|
||||
apply changes deck =
|
||||
applyPatchToDeck (changes |> toPatch) deck
|
||||
|
||||
|
||||
undo : List Change -> Deck -> Result String Deck
|
||||
undo changes deck =
|
||||
applyPatchToDeck (changes |> toPatch |> Json.invert) deck
|
||||
|
||||
|
||||
toPatch : List Change -> Json.Patch
|
||||
toPatch changes =
|
||||
changes |> List.map toOperation
|
||||
|
||||
|
||||
asContextForError : String -> List Change -> Bool -> Html msg
|
||||
asContextForError error changes undoing =
|
||||
let
|
||||
u =
|
||||
if undoing then
|
||||
Json.invert
|
||||
|
||||
else
|
||||
identity
|
||||
in
|
||||
Html.div [ HtmlA.class "error-with-context" ]
|
||||
[ Html.span [ HtmlA.class "message" ] [ Html.text error ]
|
||||
, Html.span [ HtmlA.class "change" ]
|
||||
[ changes |> toPatch |> u |> Json.toPatch |> Json.Patch.encoder |> Json.encode 2 |> Html.text ]
|
||||
]
|
||||
|
||||
|
||||
fromEditor : CardEditor -> Result String (List Change)
|
||||
fromEditor editor =
|
||||
let
|
||||
ifChanged wrap index old new =
|
||||
if old /= new then
|
||||
[ Replace index old new |> wrap ]
|
||||
|
||||
else
|
||||
[]
|
||||
in
|
||||
case editor of
|
||||
CallEditor index old new ->
|
||||
Call.editorToCall new |> Result.map (ifChanged CallChange index old)
|
||||
|
||||
ResponseEditor index old new ->
|
||||
ifChanged ResponseChange index old new |> Ok
|
||||
|
||||
NameEditor old new ->
|
||||
if old /= new then
|
||||
[ ChangeName old new ] |> Ok
|
||||
|
||||
else
|
||||
[] |> Ok
|
||||
|
||||
|
||||
applyPatchToDeck : Json.Patch -> Deck -> Result String Deck
|
||||
applyPatchToDeck patch =
|
||||
Deck.encode
|
||||
>> Json.Patch.apply (Json.toPatch patch)
|
||||
>> Result.andThen (Json.Decode.decodeValue Deck.decode >> Result.mapError Json.Decode.errorToString)
|
||||
|
||||
|
||||
toOperation : Change -> Json.Operation
|
||||
toOperation change =
|
||||
case change of
|
||||
ChangeName old newName ->
|
||||
Json.Replace [ "name" ] (old |> Json.string) (newName |> Json.string)
|
||||
|
||||
CallChange cardChange ->
|
||||
handleCardChange [ "calls" ] Call.encode cardChange
|
||||
|
||||
ResponseChange cardChange ->
|
||||
handleCardChange [ "responses" ] Response.encode cardChange
|
||||
|
||||
|
||||
handleCardChange : Json.Pointer -> (value -> Json.Value) -> CardChange value -> Json.Operation
|
||||
handleCardChange basePath encodeValue cardChange =
|
||||
case cardChange of
|
||||
Add index value ->
|
||||
Json.Add (basePath ++ [ index |> String.fromInt ]) (encodeValue value)
|
||||
|
||||
Replace index old value ->
|
||||
Json.Replace (basePath ++ [ index |> String.fromInt ]) (encodeValue old) (encodeValue value)
|
||||
|
||||
Remove index old ->
|
||||
Json.Remove (basePath ++ [ index |> String.fromInt ]) (encodeValue old)
|
||||
@@ -0,0 +1,68 @@
|
||||
module ManyDecks.Pages.Edit.Import exposing
|
||||
( importedCards
|
||||
, init
|
||||
, view
|
||||
)
|
||||
|
||||
import Cards.Call as Call exposing (Call)
|
||||
import Cards.Response as Response exposing (Response)
|
||||
import FontAwesome.Icon as Icon
|
||||
import FontAwesome.Solid as Icon
|
||||
import Html exposing (Html)
|
||||
import Html.Attributes as HtmlA
|
||||
import Html.Events as HtmlE
|
||||
import ManyDecks.Pages.Edit.Import.Model exposing (..)
|
||||
import ManyDecks.Pages.Edit.Model exposing (Msg(..))
|
||||
import Material.Button as Button
|
||||
import Material.Card as Card
|
||||
|
||||
|
||||
init : Model
|
||||
init =
|
||||
{ text = "" }
|
||||
|
||||
|
||||
view : (Msg -> msg) -> Model -> List (Html msg)
|
||||
view wrap model =
|
||||
let
|
||||
importAction =
|
||||
if String.isEmpty model.text then
|
||||
Nothing
|
||||
|
||||
else
|
||||
Import |> wrap |> Just
|
||||
in
|
||||
[ Card.view [ HtmlA.class "import" ]
|
||||
[ Html.p []
|
||||
[ Html.text "Each line will be a different card. Single underscores (“_”) represent slots. If a card "
|
||||
, Html.text "has a slot it will be a call, otherwise a response."
|
||||
]
|
||||
, Html.textarea [ HtmlA.value model.text, HtmlE.onInput (UpdateImportText >> wrap) ] []
|
||||
, Html.div [ HtmlA.class "actions" ]
|
||||
[ Button.view Button.Standard
|
||||
Button.Padded
|
||||
"Cancel"
|
||||
(Icon.arrowLeft |> Icon.viewIcon |> Just)
|
||||
(False |> SetImportVisible |> wrap |> Just)
|
||||
, Button.view Button.Standard
|
||||
Button.Padded
|
||||
"Import"
|
||||
(Icon.fileImport |> Icon.viewIcon |> Just)
|
||||
importAction
|
||||
]
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
importedCards : Model -> List ImportedCard
|
||||
importedCards model =
|
||||
let
|
||||
lineToChange line =
|
||||
case String.split "_" line of
|
||||
first :: [] ->
|
||||
Response.fromString first |> ImportedResponse
|
||||
|
||||
other ->
|
||||
Call.fromStrings other |> ImportedCall
|
||||
in
|
||||
model.text |> String.lines |> List.map lineToChange
|
||||
@@ -0,0 +1,13 @@
|
||||
module ManyDecks.Pages.Edit.Import.Model exposing (ImportedCard(..), Model)
|
||||
|
||||
import Cards.Call exposing (Call)
|
||||
import Cards.Response exposing (Response)
|
||||
|
||||
|
||||
type alias Model =
|
||||
{ text : String }
|
||||
|
||||
|
||||
type ImportedCard
|
||||
= ImportedCall Call
|
||||
| ImportedResponse Response
|
||||
@@ -0,0 +1,71 @@
|
||||
module ManyDecks.Pages.Edit.Model exposing
|
||||
( CardChange(..)
|
||||
, CardEditor(..)
|
||||
, Change(..)
|
||||
, EditError(..)
|
||||
, Model
|
||||
, Msg(..)
|
||||
, UpdateEditor(..)
|
||||
)
|
||||
|
||||
import Cards.Call exposing (Call)
|
||||
import Cards.Deck as Deck
|
||||
import Cards.Response exposing (Response)
|
||||
import Http
|
||||
import ManyDecks.Pages.Decks.Deck as Deck
|
||||
import ManyDecks.Pages.Edit.CallEditor.Model as CallEditor
|
||||
import ManyDecks.Pages.Edit.Import.Model as Import
|
||||
|
||||
|
||||
type CardEditor
|
||||
= NameEditor String String
|
||||
| CallEditor Int Call CallEditor.Model
|
||||
| ResponseEditor Int Response Response
|
||||
|
||||
|
||||
type Msg
|
||||
= StartEditing CardEditor
|
||||
| Edit UpdateEditor
|
||||
| EndEditing
|
||||
| Delete
|
||||
| Undo
|
||||
| Redo
|
||||
| SetDeletionEnabled Bool
|
||||
| ApplyChange Change
|
||||
| SetImportVisible Bool
|
||||
| Import
|
||||
| UpdateImportText String
|
||||
|
||||
|
||||
type alias Model =
|
||||
{ code : Deck.Code
|
||||
, deck : Deck.Deck
|
||||
, editing : Maybe CardEditor
|
||||
, changes : List Change
|
||||
, redoStack : List Change
|
||||
, errors : List EditError
|
||||
, deletionEnabled : Bool
|
||||
, importer : Maybe Import.Model
|
||||
}
|
||||
|
||||
|
||||
type UpdateEditor
|
||||
= UpdateName String
|
||||
| UpdateCall CallEditor.Msg
|
||||
| UpdateResponse Response
|
||||
|
||||
|
||||
type Change
|
||||
= ChangeName String String
|
||||
| CallChange (CardChange Call)
|
||||
| ResponseChange (CardChange Response)
|
||||
|
||||
|
||||
type CardChange value
|
||||
= Add Int value
|
||||
| Replace Int value value
|
||||
| Remove Int value
|
||||
|
||||
|
||||
type EditError
|
||||
= ChangeError String (List Change) Bool
|
||||
@@ -0,0 +1,39 @@
|
||||
module ManyDecks.Pages.Login exposing (..)
|
||||
|
||||
import FontAwesome.Icon as Icon
|
||||
import FontAwesome.Solid as Icon
|
||||
import Html
|
||||
import Html.Attributes as HtmlA
|
||||
import ManyDecks.Messages exposing (Msg(..))
|
||||
import Material.Button as Button
|
||||
import Material.Card as Card
|
||||
|
||||
|
||||
view : Html.Html Msg
|
||||
view =
|
||||
Card.view [ HtmlA.class "log-in" ]
|
||||
[ Html.h1 [] [ Icon.boxOpen |> Icon.viewIcon, Html.text "Many Decks" ]
|
||||
, Html.span [ HtmlA.class "version" ] [ Html.text "alpha" ]
|
||||
, Html.p []
|
||||
[ Html.text "Create decks for "
|
||||
, Html.a [ HtmlA.target "_blank", HtmlA.href "https://md.rereadgames.com" ] [ Html.text "Massive Decks" ]
|
||||
, Html.text "."
|
||||
]
|
||||
, Html.p []
|
||||
[ Html.text "This is a very early version, produced quickly in response to Cardcast's demise, there will "
|
||||
, Html.text "likely be bugs. Please report any you find "
|
||||
, Html.a [ HtmlA.target "_blank", HtmlA.href "https://github.com/Lattyware/manydecks" ]
|
||||
[ Html.text "on GitHub" ]
|
||||
]
|
||||
, Html.p []
|
||||
[ Html.text "Currently the data for this service is not backed up! Please keep local copies of your "
|
||||
, Html.text "decks as well, just in case something goes wrong."
|
||||
]
|
||||
, Html.div [ HtmlA.id "google-sign-in" ]
|
||||
[ Button.view Button.Raised
|
||||
Button.Padded
|
||||
"Sign in with Google"
|
||||
(Html.div [ HtmlA.class "google-icon" ] [] |> Just)
|
||||
(Just TryGoogleAuth)
|
||||
]
|
||||
]
|
||||
@@ -0,0 +1,172 @@
|
||||
module ManyDecks.Pages.Profile exposing
|
||||
( update
|
||||
, view
|
||||
)
|
||||
|
||||
import FontAwesome.Icon as Icon
|
||||
import FontAwesome.Solid as Icon
|
||||
import Html exposing (Html)
|
||||
import Html.Attributes as HtmlA
|
||||
import Http
|
||||
import Json.Encode
|
||||
import ManyDecks.Auth as Auth exposing (Auth)
|
||||
import ManyDecks.Pages.Profile.Model exposing (..)
|
||||
import Material.Button as Button
|
||||
import Material.Card as Card
|
||||
import Material.Switch as Switch
|
||||
import Material.TextField as TextField
|
||||
|
||||
|
||||
update : msg -> (Auth -> msg) -> (Msg -> msg) -> String -> Msg -> Model -> ( Model, Cmd msg )
|
||||
update signOut updateAuth wrap token msg model =
|
||||
case msg of
|
||||
SetUsername username ->
|
||||
( { model | name = username }, Cmd.none )
|
||||
|
||||
SetViewingProfile viewing ->
|
||||
( { model | viewing = viewing }, Cmd.none )
|
||||
|
||||
SetDeletionEnabled enabled ->
|
||||
( { model | deletionEnabled = enabled }, Cmd.none )
|
||||
|
||||
Save newName ->
|
||||
let
|
||||
handle result =
|
||||
case result of
|
||||
Ok newAuth ->
|
||||
updateAuth newAuth
|
||||
|
||||
Err error ->
|
||||
Error error |> wrap
|
||||
in
|
||||
( model, save token newName handle )
|
||||
|
||||
Delete ->
|
||||
( model, delete signOut token )
|
||||
|
||||
Error error ->
|
||||
( model, Cmd.none )
|
||||
|
||||
|
||||
view : (Msg -> msg) -> msg -> Auth -> Model -> List (Html msg)
|
||||
view wrap backup auth model =
|
||||
[ Card.view [ HtmlA.class "profile" ]
|
||||
[ editSection wrap auth model
|
||||
, backupSection backup
|
||||
, deleteSection wrap model
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
editSection : (Msg -> msg) -> Auth -> Model -> Html msg
|
||||
editSection wrap auth { name } =
|
||||
let
|
||||
title =
|
||||
Html.h2 [] [ Html.text "Profile" ]
|
||||
|
||||
editName =
|
||||
TextField.view "Username" TextField.Text name (SetUsername >> wrap |> Just)
|
||||
|
||||
description =
|
||||
Html.p [] [ Html.text "This name will be displayed publicly as the author of any deck you create." ]
|
||||
|
||||
saveAction =
|
||||
if name /= auth.name then
|
||||
name |> Save |> wrap |> Just
|
||||
|
||||
else
|
||||
Nothing
|
||||
|
||||
button =
|
||||
Button.view Button.Raised Button.Padded "Save" (Icon.save |> Icon.viewIcon |> Just) saveAction
|
||||
in
|
||||
Html.div [ HtmlA.class "edit section" ] [ title, editName, description, button ]
|
||||
|
||||
|
||||
backupSection : msg -> Html msg
|
||||
backupSection backup =
|
||||
let
|
||||
title =
|
||||
Html.h3 [] [ Html.text "Backup" ]
|
||||
|
||||
description =
|
||||
Html.p [] [ Html.text "Download a zip archive of all of your decks." ]
|
||||
|
||||
button =
|
||||
Button.view
|
||||
Button.Raised
|
||||
Button.Padded
|
||||
"Backup Decks"
|
||||
(Icon.download |> Icon.viewIcon |> Just)
|
||||
(backup |> Just)
|
||||
in
|
||||
Html.div [ HtmlA.class "backup section" ] [ title, description, button ]
|
||||
|
||||
|
||||
deleteSection : (Msg -> msg) -> Model -> Html msg
|
||||
deleteSection wrap { deletionEnabled } =
|
||||
let
|
||||
title =
|
||||
Html.h3 [] [ Html.text "Deletion" ]
|
||||
|
||||
warning =
|
||||
Html.p []
|
||||
[ Html.text "This will "
|
||||
, Html.strong [] [ Html.text "permanently delete" ]
|
||||
, Html.text " your profile and "
|
||||
, Html.em [] [ Html.text "all your decks" ]
|
||||
, Html.text ". Once done, there is "
|
||||
, Html.em [] [ Html.text "no way" ]
|
||||
, Html.text " to recover that data. We highly recommend you do a backup before this."
|
||||
]
|
||||
|
||||
sureSwitch =
|
||||
Switch.view
|
||||
(Html.span [] [ Html.text "I am sure that I want to permanently delete my profile and all my decks." ])
|
||||
deletionEnabled
|
||||
(SetDeletionEnabled >> wrap |> Just)
|
||||
|
||||
deleteAction =
|
||||
if deletionEnabled then
|
||||
Delete |> wrap |> Just
|
||||
|
||||
else
|
||||
Nothing
|
||||
|
||||
deleteButton =
|
||||
Button.view
|
||||
Button.Unelevated
|
||||
Button.Padded
|
||||
"Delete Profile"
|
||||
(Icon.trash |> Icon.viewIcon |> Just)
|
||||
deleteAction
|
||||
in
|
||||
Html.div [ HtmlA.class "delete section" ]
|
||||
[ title, warning, sureSwitch, deleteButton ]
|
||||
|
||||
|
||||
save : String -> String -> (Result Http.Error Auth.Auth -> msg) -> Cmd msg
|
||||
save token name toMsg =
|
||||
Http.post
|
||||
{ url = "/api/users"
|
||||
, body =
|
||||
[ ( "token", token |> Json.Encode.string )
|
||||
, ( "name", name |> Json.Encode.string )
|
||||
]
|
||||
|> Json.Encode.object
|
||||
|> Http.jsonBody
|
||||
, expect = Http.expectJson toMsg Auth.decoder
|
||||
}
|
||||
|
||||
|
||||
delete : msg -> String -> Cmd msg
|
||||
delete signOut token =
|
||||
Http.request
|
||||
{ method = "DELETE"
|
||||
, headers = []
|
||||
, url = "/api/users"
|
||||
, body = [ ( "token", token |> Json.Encode.string ) ] |> Json.Encode.object |> Http.jsonBody
|
||||
, expect = Http.expectWhatever (always signOut)
|
||||
, timeout = Nothing
|
||||
, tracker = Nothing
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
module ManyDecks.Pages.Profile.Model exposing
|
||||
( Model
|
||||
, Msg(..)
|
||||
, init
|
||||
)
|
||||
|
||||
import Http
|
||||
import ManyDecks.Auth exposing (Auth)
|
||||
|
||||
|
||||
type Msg
|
||||
= SetUsername String
|
||||
| SetViewingProfile Bool
|
||||
| SetDeletionEnabled Bool
|
||||
| Delete
|
||||
| Save String
|
||||
| Error Http.Error
|
||||
|
||||
|
||||
type alias Model =
|
||||
{ viewing : Bool
|
||||
, deletionEnabled : Bool
|
||||
, name : String
|
||||
}
|
||||
|
||||
|
||||
init : Auth -> Model
|
||||
init auth =
|
||||
{ viewing = False
|
||||
, deletionEnabled = False
|
||||
, name = auth.name
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
port module ManyDecks.Ports exposing (..)
|
||||
|
||||
import Json.Decode as Json
|
||||
import ManyDecks.Auth as Auth
|
||||
|
||||
|
||||
port tryGoogleAuth : () -> Cmd msg
|
||||
|
||||
|
||||
port googleAuthResult : (Json.Value -> msg) -> Sub msg
|
||||
|
||||
|
||||
port json5Decode : String -> Cmd msg
|
||||
|
||||
|
||||
port json5Decoded : (Json.Value -> msg) -> Sub msg
|
||||
|
||||
|
||||
port storeAuth : Maybe Auth.Auth -> Cmd msg
|
||||
|
||||
|
||||
port copy : String -> Cmd msg
|
||||
@@ -0,0 +1,39 @@
|
||||
type Token = string;
|
||||
|
||||
interface Auth {
|
||||
token: Token;
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface Flags {
|
||||
auth?: Auth;
|
||||
}
|
||||
|
||||
type GoogleAuthResult = { code: string } | { error: string };
|
||||
|
||||
export interface InboundPort<T> {
|
||||
subscribe(callback: (data: T) => void): void;
|
||||
}
|
||||
|
||||
export interface OutboundPort<T> {
|
||||
send(data: T): void;
|
||||
}
|
||||
|
||||
export namespace Elm {
|
||||
namespace ManyDecks {
|
||||
export interface App {
|
||||
ports: {
|
||||
tryGoogleAuth: InboundPort<null>;
|
||||
googleAuthResult: OutboundPort<GoogleAuthResult>;
|
||||
json5Decode: InboundPort<string>;
|
||||
json5Decoded: OutboundPort<object>;
|
||||
storeAuth: InboundPort<Auth | undefined>;
|
||||
copy: InboundPort<string>;
|
||||
};
|
||||
}
|
||||
export function init(options: {
|
||||
node?: HTMLElement | null;
|
||||
flags: Flags;
|
||||
}): Elm.ManyDecks.App;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Many Decks</title>
|
||||
<meta name="description" content="Build decks for Massive Decks." />
|
||||
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
<link rel="icon" type="image/svg+xml" href="../../assets/images/icon.svg" sizes="192x192">
|
||||
<link rel="icon" type="image/png" href="../../assets/images/icon.png" sizes="64x64">
|
||||
<meta name="theme-color" content="#00796b">
|
||||
|
||||
<script src="https://apis.google.com/js/platform.js?onload=init" async defer></script>
|
||||
|
||||
<link href="../scss/many-decks.scss" type="text/css" rel="stylesheet"/>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,70 @@
|
||||
.decks {
|
||||
min-width: 18em;
|
||||
max-width: 30em;
|
||||
margin: 3em;
|
||||
|
||||
.controls {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
ul {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
|
||||
.deck {
|
||||
margin: 0.5em;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
overflow: hidden;
|
||||
|
||||
.deck-code {
|
||||
margin-right: 1em;
|
||||
cursor: copy;
|
||||
}
|
||||
|
||||
.details {
|
||||
display: flex;
|
||||
flex-grow: 1;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
background-color: #cccccc;
|
||||
}
|
||||
|
||||
.name {
|
||||
flex-shrink: 1;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
min-width: 1em;
|
||||
}
|
||||
}
|
||||
|
||||
.cards {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin-left: 1em;
|
||||
|
||||
.calls {
|
||||
background-color: #000000;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.calls,
|
||||
.responses {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 0.1em;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
@use "./edit/import";
|
||||
|
||||
.edit {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin: 3em;
|
||||
|
||||
.cards {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.calls,
|
||||
.responses {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
flex-basis: 50%;
|
||||
|
||||
li {
|
||||
padding: 0.25em;
|
||||
cursor: pointer;
|
||||
min-height: 1.2em;
|
||||
|
||||
&:empty::after {
|
||||
display: block;
|
||||
content: "(Click To Edit)";
|
||||
text-align: center;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
&.add {
|
||||
&:hover {
|
||||
background-color: inherit;
|
||||
}
|
||||
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.calls {
|
||||
color: #ffffff;
|
||||
background-color: #000000;
|
||||
|
||||
li {
|
||||
&:hover {
|
||||
background-color: #333333;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.responses {
|
||||
li {
|
||||
&:hover {
|
||||
background-color: #cccccc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
|
||||
.delete {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
|
||||
mwc-button {
|
||||
--mdc-theme-primary: #ff0000;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.overlay {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
right: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
overflow: auto;
|
||||
|
||||
.background {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
|
||||
background-color: transparentize(#cccccc, 0.7);
|
||||
}
|
||||
|
||||
.errors {
|
||||
.change {
|
||||
white-space: pre;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.editing {
|
||||
user-select: none;
|
||||
|
||||
.cursor {
|
||||
border-left: 1px solid #ffffff;
|
||||
}
|
||||
|
||||
.selected {
|
||||
background-color: #4285f4;
|
||||
}
|
||||
|
||||
.spacer {
|
||||
display: block;
|
||||
flex-basis: 0;
|
||||
flex-grow: 1;
|
||||
height: 1.2em;
|
||||
}
|
||||
}
|
||||
|
||||
.editing-controls {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin-top: 0.5em;
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
.log-in {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
|
||||
min-width: 18em;
|
||||
max-width: 30em;
|
||||
margin: 3em;
|
||||
|
||||
position: relative;
|
||||
|
||||
h1 {
|
||||
margin: 0.5em;
|
||||
|
||||
> svg {
|
||||
margin-right: 0.25em;
|
||||
}
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 0.5em;
|
||||
}
|
||||
|
||||
.version {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
margin-right: -1em;
|
||||
margin-top: -1.5em;
|
||||
|
||||
width: 3em;
|
||||
height: 3em;
|
||||
|
||||
background-color: #d81b60;
|
||||
color: #ffffff;
|
||||
|
||||
border-radius: 1.5em;
|
||||
|
||||
font-size: 1.5em;
|
||||
|
||||
transform: rotateZ(10deg);
|
||||
|
||||
box-shadow: 0.15em 0.15em 0.4em transparentize(#000000, 0.7),
|
||||
-0.05em -0.05em 0.4em transparentize(#000000, 0.7);
|
||||
|
||||
transition: box-shadow 0.5s, margin-top 0.5s;
|
||||
|
||||
&:hover {
|
||||
margin-top: -2em;
|
||||
box-shadow: 0.3em 0.3em 0.4em transparentize(#000000, 0.7),
|
||||
-0.05em -0.05em 0.4em transparentize(#000000, 0.7);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#google-sign-in mwc-button {
|
||||
--mdc-theme-primary: #4285f4;
|
||||
--mdc-theme-on-primary: #ffffff;
|
||||
--mdc-button-horizontal-padding: 0.5em;
|
||||
--mdc-shape-small: 0;
|
||||
margin: 0.5em;
|
||||
|
||||
> span {
|
||||
padding: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-left: 1em;
|
||||
}
|
||||
|
||||
.google-icon {
|
||||
background-image: url("../../assets/images/google/normal.svg");
|
||||
background-size: 100% 100%;
|
||||
width: 2em;
|
||||
height: 2em;
|
||||
margin: 0 0.5em 0 -1em;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
&:disabled .google-icon {
|
||||
background-image: url("../../assets/images/google/disabled.svg");
|
||||
}
|
||||
|
||||
&:focus .google-icon {
|
||||
background-image: url("../../assets/images/google/focus.svg");
|
||||
}
|
||||
|
||||
&:active .google-icon {
|
||||
background-image: url("../../assets/images/google/pressed.svg");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
.profile {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
margin: 3em;
|
||||
|
||||
.section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin: 0.5em;
|
||||
}
|
||||
|
||||
.delete {
|
||||
--mdc-theme-primary: #ff0000;
|
||||
|
||||
mwc-button {
|
||||
margin-top: 0.5em;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,283 @@
|
||||
@use "./_colors";
|
||||
@use "./_size";
|
||||
|
||||
.game-card {
|
||||
@include size.fluid-type(20rem, 64rem, 0.5rem, 0.8rem);
|
||||
|
||||
display: inline-block;
|
||||
|
||||
transition: transform 1s;
|
||||
transform: rotateY(0turn);
|
||||
transform-style: preserve-3d;
|
||||
transform-origin: right center;
|
||||
|
||||
text-rendering: optimizeLegibility;
|
||||
font-family: "Helvetica Neue", "Nimbus Sans L", sans-serif;
|
||||
font-weight: bold;
|
||||
|
||||
$up-side: "&:not(.face-down) .side.face, &.face-down .side.reverse";
|
||||
$down-side: "&.face-down .side.face, &:not(.face-down) .side.reverse";
|
||||
|
||||
--width: #{size.$card-width};
|
||||
--aspect-ratio: #{size.$full-size};
|
||||
|
||||
&.response {
|
||||
--bg: #{colors.$response};
|
||||
--fg: #{colors.$on-response};
|
||||
|
||||
&.immutable .primary-content {
|
||||
&::first-letter {
|
||||
text-transform: capitalize;
|
||||
}
|
||||
|
||||
&::after {
|
||||
content: ".";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&.call {
|
||||
--bg: #{colors.$call};
|
||||
--fg: #{colors.$on-call};
|
||||
|
||||
.primary-content {
|
||||
p {
|
||||
display: flex;
|
||||
flex-flow: row wrap;
|
||||
align-items: stretch;
|
||||
align-content: flex-start;
|
||||
justify-content: flex-start;
|
||||
margin: 0;
|
||||
|
||||
span {
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: break-word;
|
||||
word-break: break-all;
|
||||
text-decoration: inherit;
|
||||
}
|
||||
|
||||
.text {
|
||||
display: contents;
|
||||
}
|
||||
|
||||
.slot {
|
||||
display: inline flex;
|
||||
flex-grow: 1;
|
||||
flex-basis: 2em;
|
||||
max-width: 14em;
|
||||
|
||||
&.filled {
|
||||
display: contents;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
&.empty {
|
||||
flex-grow: 1;
|
||||
border-bottom: 0.075em solid var(--fg);
|
||||
margin-bottom: 0.2em; // line-height - font-size
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.side {
|
||||
width: var(--width);
|
||||
height: calc(var(--width) * (1 / var(--aspect-ratio)));
|
||||
|
||||
backface-visibility: hidden;
|
||||
|
||||
padding: 1em;
|
||||
box-sizing: border-box;
|
||||
background: var(--bg);
|
||||
color: var(--fg);
|
||||
border-radius: 0.75em;
|
||||
border: 0.3em solid var(--bg);
|
||||
box-shadow: 0.15em 0.15em 0.4em rgba(0, 0, 0, 0.3),
|
||||
-0.05em -0.05em 0.4em rgba(0, 0, 0, 0.3);
|
||||
|
||||
&.face {
|
||||
transform: rotateY(0turn);
|
||||
}
|
||||
|
||||
&.reverse {
|
||||
transform: rotateY(0.5turn);
|
||||
|
||||
.primary-content {
|
||||
font-size: 3em;
|
||||
line-height: 1em;
|
||||
}
|
||||
}
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
|
||||
.primary-content > textarea {
|
||||
display: block;
|
||||
font: inherit;
|
||||
background-color: inherit;
|
||||
resize: none;
|
||||
border: 0;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.primary-content {
|
||||
position: relative;
|
||||
overflow: auto;
|
||||
font-size: 1.6em;
|
||||
line-height: 1.4em;
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
.secondary-content {
|
||||
margin-top: 1em;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
align-items: flex-end;
|
||||
font-size: 0.9em;
|
||||
max-width: 100%;
|
||||
|
||||
.source {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
font-size: 0.7em;
|
||||
overflow: hidden;
|
||||
margin-right: 0.5em;
|
||||
|
||||
&:before {
|
||||
content: "";
|
||||
background-image: url(../../../assets/images/deck.svg);
|
||||
background-size: 100% 100%;
|
||||
display: inline-block;
|
||||
width: 3.36em;
|
||||
height: 2.4em;
|
||||
flex-shrink: 0;
|
||||
margin-right: 0.5em;
|
||||
}
|
||||
|
||||
.name {
|
||||
flex-shrink: 1;
|
||||
height: 100%;
|
||||
min-width: 1em;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
|
||||
.instructions {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
font-size: 1.4em;
|
||||
|
||||
li {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.instruction {
|
||||
&:before,
|
||||
&:after {
|
||||
content: none;
|
||||
}
|
||||
}
|
||||
|
||||
&.face-down {
|
||||
transform: translateX(-100%) rotateY(-0.5turn);
|
||||
}
|
||||
|
||||
#{$down-side} {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
}
|
||||
|
||||
&.content-sized {
|
||||
.side {
|
||||
height: auto;
|
||||
width: auto;
|
||||
|
||||
max-width: var(--width);
|
||||
max-height: calc(var(--width) * (1 / var(--aspect-ratio)));
|
||||
}
|
||||
|
||||
#{$up-side} {
|
||||
position: relative;
|
||||
|
||||
background: none;
|
||||
border: none;
|
||||
padding: 1.75em 0 0 1.75em;
|
||||
box-shadow: none;
|
||||
|
||||
.primary-content {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.secondary-content {
|
||||
position: absolute;
|
||||
|
||||
width: var(--width);
|
||||
height: calc(var(--width) * (1 / var(--aspect-ratio)));
|
||||
|
||||
margin: -1.75em 0 0 -1.75em;
|
||||
|
||||
padding: 1em;
|
||||
box-sizing: border-box;
|
||||
background: var(--bg);
|
||||
color: var(--fg);
|
||||
border-radius: 0.75em;
|
||||
border: 0.3em solid var(--bg);
|
||||
box-shadow: 0.15em 0.15em 0.4em rgba(0, 0, 0, 0.3),
|
||||
-0.05em -0.05em 0.4em rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.instruction {
|
||||
white-space: nowrap;
|
||||
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
text-rendering: optimizeLegibility;
|
||||
|
||||
&:before {
|
||||
content: "[";
|
||||
}
|
||||
|
||||
&:after {
|
||||
content: "]";
|
||||
}
|
||||
}
|
||||
|
||||
.amount {
|
||||
display: inline-flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
white-space: nowrap;
|
||||
width: 1.2em;
|
||||
height: 1.2em;
|
||||
border-radius: 50%;
|
||||
background: var(--fg, colors.$call);
|
||||
color: var(--bg, colors.$on-call);
|
||||
margin-left: 0.3em;
|
||||
}
|
||||
|
||||
.capitalize::first-letter {
|
||||
text-transform: capitalize;
|
||||
}
|
||||
|
||||
.upper-case {
|
||||
text-transform: uppercase;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
$on-call: #ffffff;
|
||||
$call: #000000;
|
||||
|
||||
$on-response: $call;
|
||||
$response: $on-call;
|
||||
@@ -0,0 +1,25 @@
|
||||
$card-width: 18em;
|
||||
|
||||
$full-size: (5 / 7);
|
||||
$square: 1;
|
||||
|
||||
@mixin pad-to-aspect-ratio($ratio) {
|
||||
padding-bottom: #{calc(1 / #{$ratio} * 100%)};
|
||||
}
|
||||
|
||||
@function strip-unit($value) {
|
||||
@return $value / ($value * 0 + 1);
|
||||
}
|
||||
|
||||
@mixin fluid-type($min-vw, $max-vw, $min-font-size, $max-font-size) {
|
||||
font-size: $min-font-size;
|
||||
@media screen and (min-width: $min-vw) {
|
||||
font-size: calc(
|
||||
#{$min-font-size} + #{strip-unit($max-font-size - $min-font-size)} *
|
||||
((100vw - #{$min-vw}) / #{strip-unit($max-vw - $min-vw)})
|
||||
);
|
||||
}
|
||||
@media screen and (min-width: $max-vw) {
|
||||
font-size: $max-font-size;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
.import {
|
||||
flex-grow: 1;
|
||||
|
||||
align-items: stretch;
|
||||
|
||||
margin: 3em;
|
||||
|
||||
textarea {
|
||||
flex-grow: 1;
|
||||
height: 20em;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
@use "../../elm-material/src/scss/_material";
|
||||
|
||||
@use "./_edit";
|
||||
@use "./_profile";
|
||||
@use "./_decks";
|
||||
@use "./_login";
|
||||
@use "./cards/_card";
|
||||
|
||||
:root {
|
||||
font-size: 1.2em;
|
||||
|
||||
--mdc-theme-primary: #00796b;
|
||||
--mdc-theme-secondary: #d81b60;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
|
||||
min-height: 100vh;
|
||||
min-width: 100vw;
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: stretch;
|
||||
align-items: stretch;
|
||||
|
||||
background-color: #212121;
|
||||
|
||||
font-family: "Helvetica Neue", "Nimbus Sans L", sans-serif;
|
||||
}
|
||||
|
||||
.content {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
.deck-code {
|
||||
font-family: monospace;
|
||||
background-color: #00796b;
|
||||
color: #ffffff;
|
||||
padding: 0.5em;
|
||||
letter-spacing: 0.2em;
|
||||
border: none;
|
||||
flex-basis: 5em;
|
||||
min-width: 5em;
|
||||
text-align: center;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
nav {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
#sign-out {
|
||||
margin: 1em;
|
||||
}
|
||||
|
||||
#view-profile {
|
||||
margin: 1em;
|
||||
}
|
||||
|
||||
mwc-button {
|
||||
align-self: flex-end;
|
||||
}
|
||||
|
||||
.core-error {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
|
||||
background-color: transparentize(#ff0000, 0.7);
|
||||
|
||||
font-size: 3em;
|
||||
|
||||
z-index: 999;
|
||||
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
.mdc-card {
|
||||
margin: 3em;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
import "../../elm-material/src/ts/material";
|
||||
import * as Json5 from "json5";
|
||||
import { Elm } from "src/elm/ManyDecks";
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
init: () => void;
|
||||
}
|
||||
}
|
||||
|
||||
const main = async () => {
|
||||
const { Elm } = await import(
|
||||
/* webpackChunkName: "many-decks" */ "../elm/ManyDecks"
|
||||
);
|
||||
|
||||
const savedAuth = localStorage.getItem("auth");
|
||||
|
||||
const app: Elm.ManyDecks.App = Elm.ManyDecks.init({
|
||||
flags: {
|
||||
auth: savedAuth === null ? null : JSON.parse(savedAuth),
|
||||
},
|
||||
});
|
||||
|
||||
app.ports.tryGoogleAuth.subscribe((_) => {
|
||||
if (gapi.auth2 !== undefined) {
|
||||
gapi.auth2.authorize(
|
||||
{
|
||||
client_id: "CHANGE ME",
|
||||
scope: "profile openid",
|
||||
response_type: "id_token",
|
||||
},
|
||||
(response) => {
|
||||
app.ports.googleAuthResult.send(
|
||||
response.error !== undefined
|
||||
? { error: response.error }
|
||||
: { code: response.id_token }
|
||||
);
|
||||
}
|
||||
);
|
||||
} else {
|
||||
app.ports.googleAuthResult.send({
|
||||
error: "Could not connect to Google.",
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
app.ports.json5Decode.subscribe((raw) => {
|
||||
app.ports.json5Decoded.send(Json5.parse(raw));
|
||||
});
|
||||
|
||||
app.ports.storeAuth.subscribe((auth) => {
|
||||
if (auth !== undefined) {
|
||||
localStorage.setItem("auth", JSON.stringify(auth));
|
||||
} else {
|
||||
localStorage.removeItem("auth");
|
||||
}
|
||||
});
|
||||
|
||||
app.ports.copy.subscribe((id) => {
|
||||
const textField = document.getElementById(id);
|
||||
if (textField !== null && textField instanceof HTMLInputElement) {
|
||||
textField.select();
|
||||
const value = textField.value;
|
||||
textField.setSelectionRange(0, value.length);
|
||||
try {
|
||||
navigator.clipboard.writeText(value).catch(console.error);
|
||||
} catch (err) {
|
||||
document.execCommand("copy");
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
main().catch(console.error);
|
||||
|
||||
window.init = () => {
|
||||
gapi.load("auth2", () => {});
|
||||
};
|
||||
if (window["gapi"] !== undefined) {
|
||||
window.init();
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "esnext",
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"preserveConstEnums": true,
|
||||
"outDir": "dist",
|
||||
"strict": true,
|
||||
"sourceMap": true,
|
||||
"baseUrl": ".",
|
||||
"moduleResolution": "node",
|
||||
"lib": [ "es2015", "dom" ]
|
||||
},
|
||||
"include": [
|
||||
"src/ts/**/*"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"dist"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
const path = require("path");
|
||||
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
||||
const sass = require("sass");
|
||||
|
||||
module.exports = (env, argv) => {
|
||||
// WebStorm doesn't give any arguments, causing this to blow up without the check.
|
||||
const mode = typeof argv === "undefined" ? "production" : argv.mode;
|
||||
|
||||
const prod = mode === "production";
|
||||
const dev = mode === "development";
|
||||
|
||||
const dist = path.resolve(__dirname, "dist");
|
||||
const src = path.resolve(__dirname, "src");
|
||||
|
||||
const plugins = [
|
||||
new HtmlWebpackPlugin({
|
||||
template: "src/html/index.html",
|
||||
filename: "index.html",
|
||||
inject: "body",
|
||||
test: /\.html$/,
|
||||
}),
|
||||
];
|
||||
|
||||
const cssLoaders = [
|
||||
// Extract to separate file.
|
||||
{
|
||||
loader: "file-loader",
|
||||
options: {
|
||||
name: prod ? "[name].[contenthash].css" : "[name].css",
|
||||
outputPath: "assets/styles",
|
||||
esModule: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
loader: "extract-loader",
|
||||
},
|
||||
// Load CSS to inline styles.
|
||||
{
|
||||
loader: "css-loader",
|
||||
options: { sourceMap: dev },
|
||||
},
|
||||
// Transform CSS for compatibility.
|
||||
// {
|
||||
// loader: "postcss-loader",
|
||||
// options: {
|
||||
// sourceMap: dev,
|
||||
// },
|
||||
// },
|
||||
// Allow relative URLs.
|
||||
{
|
||||
loader: "resolve-url-loader",
|
||||
options: { sourceMap: dev },
|
||||
},
|
||||
// Load SASS to CSS.
|
||||
{
|
||||
loader: "sass-loader",
|
||||
options: {
|
||||
implementation: sass,
|
||||
sourceMap: true,
|
||||
sassOptions: {
|
||||
includePaths: ["node_modules"],
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const elmLoaders = [
|
||||
// Load elm to JS.
|
||||
{
|
||||
loader: "elm-webpack-loader",
|
||||
options: {
|
||||
files: [path.resolve(src, "elm/ManyDecks.elm")],
|
||||
optimize: prod,
|
||||
debug: dev,
|
||||
forceWatch: dev,
|
||||
cwd: __dirname,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
return {
|
||||
context: path.resolve(__dirname),
|
||||
entry: {
|
||||
index: "./src/ts/index.ts",
|
||||
},
|
||||
devtool: prod ? undefined : "eval-source-map",
|
||||
output: {
|
||||
path: dist,
|
||||
publicPath: "/",
|
||||
filename: prod ? "[name].[contenthash].js" : "[name].js",
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
// HTML
|
||||
{
|
||||
test: /\.html$/,
|
||||
exclude: [/elm-stuff/, /node_modules/],
|
||||
use: [
|
||||
{
|
||||
loader: "html-loader",
|
||||
options: {
|
||||
attributes: {
|
||||
list: [
|
||||
{
|
||||
tag: "img",
|
||||
attribute: "src",
|
||||
type: "src",
|
||||
},
|
||||
{
|
||||
tag: "link",
|
||||
attribute: "href",
|
||||
type: "src",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
// Elm.
|
||||
{
|
||||
test: /\.elm$/,
|
||||
exclude: [/elm-stuff/, /node_modules/],
|
||||
use: elmLoaders,
|
||||
},
|
||||
// Typescript scripts.
|
||||
{
|
||||
test: /\.ts$/,
|
||||
exclude: [/elm-stuff/, /node_modules/],
|
||||
use: "ts-loader",
|
||||
include: src,
|
||||
},
|
||||
// Styles.
|
||||
{
|
||||
test: /\.s?css$/,
|
||||
exclude: [/elm-stuff/, /node_modules/],
|
||||
use: cssLoaders,
|
||||
},
|
||||
// Image assets.
|
||||
{
|
||||
test: /\.(jpg|png|svg)$/,
|
||||
loader: "file-loader",
|
||||
options: {
|
||||
name: prod
|
||||
? "assets/images/[name].[contenthash].[ext]"
|
||||
: "assets/images/[name].[ext]",
|
||||
esModule: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
resolve: {
|
||||
extensions: [".js", ".ts", ".elm", ".scss"],
|
||||
modules: ["node_modules"],
|
||||
},
|
||||
plugins,
|
||||
devServer: {
|
||||
hot: true,
|
||||
allowedHosts: ["localhost"],
|
||||
proxy: {
|
||||
// Forward to the server.
|
||||
"/api/**": {
|
||||
target: "http://localhost:8083",
|
||||
ws: true,
|
||||
},
|
||||
// As we are an SPA, this lets us route all requests to the index.
|
||||
"**": {
|
||||
target: "http://localhost:8082",
|
||||
pathRewrite: {
|
||||
".*": "",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,47 @@
|
||||
version: "3"
|
||||
|
||||
networks:
|
||||
internal:
|
||||
|
||||
volumes:
|
||||
storage-volume:
|
||||
|
||||
services:
|
||||
storage:
|
||||
container_name: postgres
|
||||
image: "postgres:12"
|
||||
environment:
|
||||
- POSTGRES_USER=manydecks
|
||||
- POSTGRES_PASSWORD=manydecks
|
||||
networks:
|
||||
- internal
|
||||
volumes:
|
||||
- storage-volume:/var/lib/postgresql/data
|
||||
restart: unless-stopped
|
||||
|
||||
server:
|
||||
container_name: server
|
||||
image: "manydecks/server:dev"
|
||||
build: "./server"
|
||||
depends_on:
|
||||
- storage
|
||||
environment:
|
||||
- NODE_ENV=production
|
||||
networks:
|
||||
- internal
|
||||
restart: unless-stopped
|
||||
|
||||
client:
|
||||
container_name: client
|
||||
image: "manydecks/client:dev"
|
||||
build: "./client"
|
||||
depends_on:
|
||||
- server
|
||||
ports:
|
||||
- "80:8080"
|
||||
- "443:8083"
|
||||
networks:
|
||||
- internal
|
||||
volumes:
|
||||
- /home/ubuntu/nginx.conf:/etc/nginx/nginx.conf:ro
|
||||
restart: unless-stopped
|
||||
@@ -0,0 +1,42 @@
|
||||
FROM node:14-alpine
|
||||
|
||||
WORKDIR /md
|
||||
|
||||
COPY ["./package.json", "./package-lock.json", "./"]
|
||||
RUN ["npm", "ci"]
|
||||
|
||||
COPY ["./src", "./src"]
|
||||
COPY ["./tsconfig.json", "./config.json5", "./"]
|
||||
RUN ["npm", "run", "build"]
|
||||
|
||||
FROM node:14-alpine
|
||||
LABEL maintainer="team@rereadgames.com"
|
||||
|
||||
ARG BUILD_DATE
|
||||
ARG VCS_REF
|
||||
ARG VERSION=dev
|
||||
|
||||
ENV MD_VERSION $VERSION
|
||||
|
||||
LABEL org.label-schema.name="manydecks/server"
|
||||
LABEL org.label-schema.description="The web server for Many Decks, a deck source for Massive Decks."
|
||||
LABEL org.label-schema.url="https://github.com/Lattyware/manydecks"
|
||||
LABEL org.label-schema.vcs-url="https://github.com/Lattyware/manydecks"
|
||||
LABEL org.label-schema.vendor="Reread Games"
|
||||
LABEL org.label-schema.schema-version="1.0"
|
||||
LABEL org.label-schema.build-date=$BUILD_DATE
|
||||
LABEL org.label-schema.vcs-ref=$VCS_REF
|
||||
LABEL org.label-schema.version=$VERSION
|
||||
|
||||
WORKDIR /md
|
||||
|
||||
COPY ["./package.json", "./package-lock.json", "./"]
|
||||
RUN ["npm", "ci", "--only=production"]
|
||||
|
||||
COPY ["./src/sql", "./src/sql"]
|
||||
COPY ["./config.json5", "./"]
|
||||
COPY --from=0 ["/md/dist", "./"]
|
||||
|
||||
EXPOSE 8081
|
||||
USER node
|
||||
CMD ["node", "--es-module-specifier-resolution=node", "./index.js"]
|
||||
@@ -0,0 +1,27 @@
|
||||
{
|
||||
listenOn: 8081,
|
||||
|
||||
connection: {
|
||||
host: "postgres",
|
||||
port: 5432,
|
||||
user: "manydecks",
|
||||
database: "manydecks",
|
||||
password: "manydecks",
|
||||
keepAlive: false,
|
||||
},
|
||||
|
||||
auth: {
|
||||
local: {
|
||||
issuer: "",
|
||||
secret: "CHANGE ME",
|
||||
algorithm: "HS256",
|
||||
historicAlgorithms: [],
|
||||
expiresIn: "3h",
|
||||
},
|
||||
|
||||
google: {
|
||||
id: "CHANGE ME",
|
||||
secret: "CHANGE ME",
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
{
|
||||
"name": "@manydecks/server",
|
||||
"version": "1.0.0",
|
||||
"author": "Reread Games <team@rereadgames.com>",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"private": true,
|
||||
"description": "A place to make and share custom decks for Massive Decks.",
|
||||
"repository": "github:Lattyware/manydecks",
|
||||
"engines": {
|
||||
"node": "13.x.x"
|
||||
},
|
||||
"type": "module",
|
||||
"module": "src/index.ts",
|
||||
"scripts": {
|
||||
"build": "npx tsc",
|
||||
"prestart": "npm run build",
|
||||
"start": "node --es-module-specifier-resolution=node dist/index.js",
|
||||
"dev": "nodemon",
|
||||
"debug": "nodemon --inspect",
|
||||
"build-image": "docker build . -t \"manydecks/server\" --build-arg BUILD_DATE=\"$(date --rfc-3339=seconds)\""
|
||||
},
|
||||
"dependencies": {
|
||||
"express": "^4.17.1",
|
||||
"express-async-errors": "^3.1.1",
|
||||
"express-easy-zip": "^1.1.5",
|
||||
"express-winston": "^4.0.3",
|
||||
"fast-json-patch": "^3.0.0-1",
|
||||
"fp-ts": "^2.6.1",
|
||||
"google-auth-library": "^6.0.0",
|
||||
"hashids": "^2.2.1",
|
||||
"helmet": "^3.22.0",
|
||||
"http-status-codes": "^1.4.0",
|
||||
"io-ts": "^2.2.2",
|
||||
"json5": "^2.1.3",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"node-pg-migrate": "^4.8.0",
|
||||
"pg": "^8.2.1",
|
||||
"postgres-migrations": "^4.0.3",
|
||||
"source-map-support": "^0.5.19",
|
||||
"uuid": "^8.0.0",
|
||||
"winston": "^3.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/express": "^4.17.6",
|
||||
"@types/express-winston": "^4.0.0",
|
||||
"@types/fast-json-patch": "^1.1.5",
|
||||
"@types/hashids": "^1.0.30",
|
||||
"@types/helmet": "0.0.47",
|
||||
"@types/json5": "0.0.30",
|
||||
"@types/jsonwebtoken": "^8.5.0",
|
||||
"@types/pg": "^7.14.3",
|
||||
"@types/source-map-support": "^0.5.1",
|
||||
"@types/uuid": "^7.0.3",
|
||||
"@typescript-eslint/eslint-plugin": "^2.33.0",
|
||||
"@typescript-eslint/parser": "^2.33.0",
|
||||
"eslint": "^7.0.0",
|
||||
"eslint-config-prettier": "^6.11.0",
|
||||
"eslint-plugin-prettier": "^3.1.3",
|
||||
"nodemon": "^2.0.4",
|
||||
"prettier": "^2.0.5",
|
||||
"typescript": "^3.9.2"
|
||||
},
|
||||
"nodemonConfig": {
|
||||
"watch": [
|
||||
"src/"
|
||||
],
|
||||
"ext": "ts,sql",
|
||||
"exec": "npm run start"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
CREATE SCHEMA IF NOT EXISTS manydecks;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS manydecks.meta (
|
||||
id bool PRIMARY KEY DEFAULT TRUE,
|
||||
issuer UUID NOT NULL,
|
||||
CONSTRAINT id CHECK (id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS manydecks.users (
|
||||
id TEXT NOT NULL PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
google_id TEXT NOT NULL,
|
||||
UNIQUE (google_id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS manydecks.decks (
|
||||
id SERIAL PRIMARY KEY,
|
||||
version INTEGER NOT NULL DEFAULT 0,
|
||||
author TEXT NOT NULL,
|
||||
deck JSONB NOT NULL,
|
||||
FOREIGN KEY (author) REFERENCES manydecks.users (id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE OR REPLACE VIEW manydecks.summaries AS
|
||||
SELECT
|
||||
decks.id,
|
||||
users.name as author,
|
||||
users.id as author_id,
|
||||
decks.version,
|
||||
decks.deck->'name' as name,
|
||||
decks.deck->'language' as language,
|
||||
jsonb_array_length(decks.deck->'calls') as calls,
|
||||
jsonb_array_length(decks.deck->'responses') as responses
|
||||
FROM
|
||||
manydecks.decks INNER JOIN manydecks.users ON users.id = decks.author;
|
||||
|
||||
CREATE OR REPLACE FUNCTION increment_version()
|
||||
RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
NEW.version = OLD.version + 1;
|
||||
return NEW;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
BEGIN;
|
||||
DROP TRIGGER IF EXISTS increment_version ON manydecks.decks;
|
||||
|
||||
CREATE TRIGGER increment_version
|
||||
BEFORE UPDATE ON manydecks.decks
|
||||
FOR EACH ROW EXECUTE PROCEDURE increment_version();
|
||||
COMMIT;
|
||||
@@ -0,0 +1,98 @@
|
||||
import { default as t } from "io-ts";
|
||||
import { default as PathReporter } from "io-ts/lib/PathReporter";
|
||||
import { default as Either } from "fp-ts/lib/Either";
|
||||
|
||||
const Style = t.keyof({
|
||||
Em: null,
|
||||
Strong: null,
|
||||
});
|
||||
export type Style = t.TypeOf<typeof Style>;
|
||||
|
||||
const Transform = t.keyof({
|
||||
UpperCase: null,
|
||||
Capitalize: null,
|
||||
});
|
||||
export type Transform = t.TypeOf<typeof Transform>;
|
||||
|
||||
const Slot = t.partial({
|
||||
transform: Transform,
|
||||
style: Style,
|
||||
});
|
||||
export type Slot = t.TypeOf<typeof Slot>;
|
||||
|
||||
const Styled = t.intersection([
|
||||
t.strict({
|
||||
text: t.string,
|
||||
}),
|
||||
t.partial({ style: Style }),
|
||||
]);
|
||||
export type Styled = t.TypeOf<typeof Styled>;
|
||||
|
||||
const Part = t.union([t.string, Styled, Slot]);
|
||||
export type Part = t.TypeOf<typeof Part>;
|
||||
|
||||
const EditableDeck = t.intersection([
|
||||
t.strict({
|
||||
name: t.string,
|
||||
calls: t.array(t.array(t.array(Part))),
|
||||
responses: t.array(t.string),
|
||||
}),
|
||||
t.partial({ language: t.string }),
|
||||
]);
|
||||
export type EditableDeck = t.TypeOf<typeof EditableDeck>;
|
||||
|
||||
const Deck = t.intersection([
|
||||
EditableDeck,
|
||||
t.strict({
|
||||
author: t.string,
|
||||
version: t.Int,
|
||||
}),
|
||||
]);
|
||||
export type Deck = t.TypeOf<typeof Deck>;
|
||||
|
||||
const Details = t.strict({
|
||||
name: t.string,
|
||||
author: t.string,
|
||||
language: t.string,
|
||||
});
|
||||
export type Details = t.TypeOf<typeof Details>;
|
||||
|
||||
const Summary = t.strict({
|
||||
details: Details,
|
||||
calls: t.Int,
|
||||
responses: t.Int,
|
||||
version: t.Int,
|
||||
});
|
||||
export type Summary = t.TypeOf<typeof Summary>;
|
||||
|
||||
const SummaryAndCode = t.strict({
|
||||
code: t.string,
|
||||
summary: Summary,
|
||||
});
|
||||
export type SummaryAndCode = t.TypeOf<typeof SummaryAndCode>;
|
||||
|
||||
const hasSlot = (call: Part[][]) => {
|
||||
for (const line of call) {
|
||||
for (const part of line) {
|
||||
if (typeof part !== "string" && !part.hasOwnProperty("text")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
export const validate: (maybeDeck: object) => EditableDeck = (maybeDeck) => {
|
||||
const result = EditableDeck.decode(maybeDeck);
|
||||
const report = PathReporter.PathReporter.report(result);
|
||||
if (Either.isLeft(result)) {
|
||||
throw new Error(report.join("\n"));
|
||||
} else {
|
||||
for (const call of result.right.calls) {
|
||||
if (!hasSlot(call)) {
|
||||
throw new Error("Calls must contain at least one slot.");
|
||||
}
|
||||
}
|
||||
return result.right;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,18 @@
|
||||
import Hashids from "hashids";
|
||||
import * as Errors from "../errors";
|
||||
|
||||
const hashIds = new Hashids(
|
||||
"manydecks",
|
||||
5,
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
);
|
||||
|
||||
export const decode = (code: string): number => {
|
||||
try {
|
||||
return Number(hashIds.decode(code)[0]);
|
||||
} catch (error) {
|
||||
throw new Errors.DeckNotFound();
|
||||
}
|
||||
};
|
||||
|
||||
export const encode = (id: number): string => hashIds.encode(id);
|
||||
@@ -0,0 +1,66 @@
|
||||
import HttpStatus from "http-status-codes";
|
||||
|
||||
export abstract class ManyDecksError extends Error {
|
||||
public abstract readonly type: string;
|
||||
public abstract readonly status: number;
|
||||
|
||||
protected constructor(message: string) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public error(): object {
|
||||
return {
|
||||
error: this.type,
|
||||
...this.details(),
|
||||
};
|
||||
}
|
||||
|
||||
protected details(): object {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
export class PatchTestFailed extends ManyDecksError {
|
||||
public readonly type = "PatchTestFailed";
|
||||
public readonly status = HttpStatus.PRECONDITION_FAILED;
|
||||
|
||||
public constructor() {
|
||||
super("There was a conflict.");
|
||||
}
|
||||
}
|
||||
|
||||
export class BadDeck extends ManyDecksError {
|
||||
public readonly type = "BadDeck";
|
||||
public readonly status = HttpStatus.BAD_REQUEST;
|
||||
|
||||
public constructor() {
|
||||
super("The given deck was invalid.");
|
||||
}
|
||||
}
|
||||
|
||||
export class BadPatch extends ManyDecksError {
|
||||
public readonly type = "BadPatch";
|
||||
public readonly status = HttpStatus.BAD_REQUEST;
|
||||
|
||||
public constructor() {
|
||||
super("The given patch was invalid or produced invalid results.");
|
||||
}
|
||||
}
|
||||
|
||||
export class DeckNotFound extends ManyDecksError {
|
||||
public readonly type = "DeckNotFound";
|
||||
public readonly status = HttpStatus.NOT_FOUND;
|
||||
|
||||
public constructor() {
|
||||
super("Deck not found.");
|
||||
}
|
||||
}
|
||||
|
||||
export class AuthFailure extends ManyDecksError {
|
||||
public readonly type = "AuthFailure";
|
||||
public readonly status = HttpStatus.BAD_REQUEST;
|
||||
|
||||
public constructor() {
|
||||
super("Authentication failure.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
import expressWinston from "express-winston";
|
||||
import bodyParser from "body-parser";
|
||||
import helmet from "helmet";
|
||||
import sourceMapSupport from "source-map-support";
|
||||
import * as Logging from "./logging";
|
||||
import express, { NextFunction, Request, Response } from "express";
|
||||
import "express-async-errors";
|
||||
import HttpStatus from "http-status-codes";
|
||||
import * as Code from "./deck/code";
|
||||
import Json5 from "json5";
|
||||
import { promises as fs } from "fs";
|
||||
import * as Store from "./store";
|
||||
import * as Errors from "./errors";
|
||||
import * as Auth from "./user/auth";
|
||||
import { default as GoogleAuth } from "google-auth-library";
|
||||
import * as Uuid from "uuid";
|
||||
// @ts-ignore
|
||||
import { default as Zip } from "express-easy-zip";
|
||||
|
||||
sourceMapSupport.install();
|
||||
|
||||
process.on("uncaughtException", function (error) {
|
||||
Logging.logException("Uncaught exception: ", error);
|
||||
});
|
||||
|
||||
process.on("unhandledRejection", function (reason, promise) {
|
||||
if (reason instanceof Error) {
|
||||
Logging.logException(`Unhandled rejection for ${promise}.`, reason);
|
||||
} else {
|
||||
Logging.logger.error(`Unhandled rejection at ${promise}: ${reason}`);
|
||||
}
|
||||
});
|
||||
|
||||
const main = async (): Promise<void> => {
|
||||
const config = Json5.parse((await fs.readFile("config.json5")).toString());
|
||||
|
||||
const store = await Store.init(config.connection);
|
||||
const auth = new Auth.Auth(config.auth.local);
|
||||
|
||||
const google = new GoogleAuth.OAuth2Client(config.auth.google.id);
|
||||
|
||||
const app = express();
|
||||
|
||||
app.use(helmet());
|
||||
app.set("trust proxy", true);
|
||||
app.use(bodyParser.json());
|
||||
app.use(Zip());
|
||||
|
||||
app.use(
|
||||
expressWinston.logger({
|
||||
winstonInstance: Logging.logger,
|
||||
})
|
||||
);
|
||||
|
||||
app.post("/api/users", async (req, res) => {
|
||||
if (req.body.token !== undefined) {
|
||||
const claims = auth.validate(req.body.token);
|
||||
const id = claims.sub;
|
||||
const name = req.body.name;
|
||||
await store.changeUser(id, name);
|
||||
res.json({ token: auth.sign({ sub: id }), name });
|
||||
return;
|
||||
} else {
|
||||
const ticket = await google.verifyIdToken({
|
||||
idToken: req.body.google,
|
||||
audience: config.auth.google.id,
|
||||
});
|
||||
const payload = ticket.getPayload();
|
||||
if (payload !== undefined) {
|
||||
const { id, name } = await store.findOrCreateUser(
|
||||
payload.sub,
|
||||
payload.name
|
||||
);
|
||||
res.json({ token: auth.sign({ sub: id }), name });
|
||||
return;
|
||||
}
|
||||
}
|
||||
res.status(HttpStatus.UNAUTHORIZED).json({ error: "NotAuthenticated" });
|
||||
});
|
||||
|
||||
app.delete("/api/users", async (req, res) => {
|
||||
const claims = auth.validate(req.body.token);
|
||||
await store.deleteUser(claims.sub);
|
||||
res.status(HttpStatus.OK);
|
||||
});
|
||||
|
||||
app.get("/api/decks/:deckCode", async (req, res) => {
|
||||
const id = Code.decode(req.params.deckCode);
|
||||
const result = await store.getDeck(id);
|
||||
res.json(result);
|
||||
});
|
||||
|
||||
app.get("/api/decks/:deckCode/summary", async (req, res) => {
|
||||
const id = Code.decode(req.params.deckCode);
|
||||
const result = await store.getSummary(id);
|
||||
res.json(result);
|
||||
});
|
||||
|
||||
app.patch("/api/decks/:deckCode", async (req, res) => {
|
||||
const id = Code.decode(req.params.deckCode);
|
||||
const claims = auth.validate(req.body.token);
|
||||
const result = await store.updateDeck(id, claims.sub, req.body.patch);
|
||||
res.json(result);
|
||||
});
|
||||
|
||||
app.post("/api/decks", async (req, res) => {
|
||||
const claims = auth.validate(req.body.token);
|
||||
const initial = req.body.initial;
|
||||
if (initial !== undefined) {
|
||||
const id = await store.create(initial, claims.sub);
|
||||
const code = Code.encode(id);
|
||||
res.status(HttpStatus.CREATED).json(code);
|
||||
} else {
|
||||
const decks = await store.getSummariesForUser(claims.sub);
|
||||
res.json(decks);
|
||||
}
|
||||
});
|
||||
|
||||
app.post("/api/backup", async (req, res) => {
|
||||
const claims = auth.validate(req.body.token);
|
||||
const files = await store.getDecks(claims.sub);
|
||||
// @ts-ignore
|
||||
res.zip({
|
||||
files: files.map((c) => {
|
||||
delete c.version;
|
||||
return {
|
||||
content: Json5.stringify(c, undefined, 2),
|
||||
name: `${c.name.replace(/\s/g, "-")}-${
|
||||
c.language
|
||||
}-${Uuid.v4()}.deck.json5`,
|
||||
};
|
||||
}),
|
||||
filename: "backup.zip",
|
||||
});
|
||||
});
|
||||
|
||||
app.delete("/api/decks/:deckCode", async (req, res) => {
|
||||
const id = Code.decode(req.params.deckCode);
|
||||
const claims = auth.validate(req.body.token);
|
||||
await store.deleteDeck(id, claims.sub);
|
||||
res.status(HttpStatus.OK);
|
||||
});
|
||||
|
||||
app.use(
|
||||
expressWinston.errorLogger({
|
||||
winstonInstance: Logging.logger,
|
||||
msg: "{{err.message}}",
|
||||
})
|
||||
);
|
||||
|
||||
app.use((error: Error, req: Request, res: Response, next: NextFunction) => {
|
||||
if (res.headersSent) {
|
||||
next(error);
|
||||
}
|
||||
if (error instanceof Errors.ManyDecksError) {
|
||||
res.status(error.status).json(error.error());
|
||||
} else {
|
||||
res
|
||||
.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
.json({ error: "InternalServerError" });
|
||||
}
|
||||
});
|
||||
|
||||
app.listen(config.listenOn, async () => {
|
||||
Logging.logger.info(`Listening on ${config.listenOn}.`);
|
||||
});
|
||||
};
|
||||
|
||||
main().catch((error) => {
|
||||
Logging.logException("Application exception:", error);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -0,0 +1,43 @@
|
||||
import winston from "winston";
|
||||
|
||||
const logFormat = winston.format.printf((info) => {
|
||||
const stringRest = JSON.stringify(
|
||||
{
|
||||
...info,
|
||||
level: undefined,
|
||||
message: undefined,
|
||||
splat: undefined,
|
||||
},
|
||||
null,
|
||||
2
|
||||
);
|
||||
|
||||
if (stringRest !== "{}") {
|
||||
return `${info.level}: ${info.message}\n${stringRest}`;
|
||||
} else {
|
||||
return `${info.level}: ${info.message}`;
|
||||
}
|
||||
});
|
||||
|
||||
export const logger = winston.createLogger({
|
||||
transports: [new winston.transports.Console()],
|
||||
format: winston.format.combine(
|
||||
winston.format.timestamp(),
|
||||
winston.format.colorize(),
|
||||
logFormat
|
||||
),
|
||||
});
|
||||
|
||||
const exceptionHandler = new winston.ExceptionHandler(logger);
|
||||
export const exceptionToMeta = exceptionHandler.getAllInfo.bind(
|
||||
exceptionHandler
|
||||
);
|
||||
|
||||
export const logException = (
|
||||
message: string,
|
||||
error: Error,
|
||||
data?: string
|
||||
): void => {
|
||||
const details = exceptionToMeta(error);
|
||||
logger.error(message, details === undefined ? details : { details, data });
|
||||
};
|
||||
@@ -0,0 +1,288 @@
|
||||
import { default as Migrate } from "postgres-migrations";
|
||||
import { default as Pg, Pool } from "pg";
|
||||
import * as Logging from "./logging";
|
||||
import * as Deck from "./deck";
|
||||
import * as Patch from "fast-json-patch";
|
||||
import { default as JsonPatch } from "fast-json-patch";
|
||||
import * as Errors from "./errors";
|
||||
import * as uuid from "uuid";
|
||||
import * as User from "./user";
|
||||
import * as Code from "./deck/code";
|
||||
|
||||
const migrateConfig = {
|
||||
logger: (msg: string) => Logging.logger.info(msg),
|
||||
};
|
||||
|
||||
export const init = async (config: Pg.PoolConfig): Promise<Store> => {
|
||||
const pool = new Pg.Pool(config);
|
||||
let issuer;
|
||||
const client = await pool.connect();
|
||||
try {
|
||||
await client.query(
|
||||
"CREATE SCHEMA IF NOT EXISTS manydecks; SET search_path = manydecks;"
|
||||
);
|
||||
await Migrate.createDb("manydecks", { client }, migrateConfig);
|
||||
await Migrate.migrate({ client }, "src/sql", migrateConfig);
|
||||
|
||||
await client.query(
|
||||
`
|
||||
INSERT INTO manydecks.meta (issuer) VALUES ($1) ON CONFLICT DO NOTHING;
|
||||
`,
|
||||
[uuid.v4()]
|
||||
);
|
||||
|
||||
const meta = await client.query(`
|
||||
SELECT issuer FROM manydecks.meta;
|
||||
`);
|
||||
|
||||
const [row] = meta.rows;
|
||||
issuer = row.issuer;
|
||||
} finally {
|
||||
client.release();
|
||||
}
|
||||
|
||||
return new Store(pool, issuer);
|
||||
};
|
||||
|
||||
export class Store {
|
||||
public readonly issuer: string;
|
||||
private readonly pool: Pg.Pool;
|
||||
|
||||
public constructor(pool: Pool, issuer: string) {
|
||||
this.pool = pool;
|
||||
this.issuer = issuer;
|
||||
}
|
||||
|
||||
public findOrCreateUser: (
|
||||
googleId: string,
|
||||
googleName: string | undefined
|
||||
) => Promise<User.User> = async (googleId, googleName) =>
|
||||
await this.withClient(async (client) => {
|
||||
const existingResult = await client.query(
|
||||
`SELECT id, name FROM manydecks.users WHERE google_id = $1;`,
|
||||
[googleId]
|
||||
);
|
||||
if (existingResult.rowCount > 0) {
|
||||
const [user] = existingResult.rows;
|
||||
return { id: user.id, name: user.name };
|
||||
} else {
|
||||
const newId = User.id();
|
||||
const newName = googleName === undefined ? "New User" : googleName;
|
||||
await client.query(
|
||||
`INSERT INTO manydecks.users (id, name, google_id) VALUES ($1, $2, $3);`,
|
||||
[newId, newName, googleId]
|
||||
);
|
||||
return { id: newId, name: newName };
|
||||
}
|
||||
});
|
||||
|
||||
public changeUser: (user: string, name: string) => Promise<void> = async (
|
||||
user,
|
||||
name
|
||||
) =>
|
||||
await this.withClient(async (client) => {
|
||||
await client.query(`UPDATE manydecks.users SET name=$2 WHERE id=$1;`, [
|
||||
user,
|
||||
name,
|
||||
]);
|
||||
});
|
||||
|
||||
public deleteUser: (user: string) => Promise<void> = async (user) =>
|
||||
await this.withClient(async (client) => {
|
||||
await client.query(`DELETE FROM manydecks.users WHERE id=$1`, [user]);
|
||||
});
|
||||
|
||||
public create: (
|
||||
d: Deck.EditableDeck,
|
||||
user: string
|
||||
) => Promise<number> = async (d, user) =>
|
||||
await this.withClient(async (client) => {
|
||||
let deck;
|
||||
try {
|
||||
deck = Deck.validate(d);
|
||||
} catch (error) {
|
||||
throw new Errors.BadDeck();
|
||||
}
|
||||
const insert = await client.query(
|
||||
`
|
||||
INSERT INTO manydecks.decks (deck, author) VALUES ($1, $2) RETURNING id;
|
||||
`,
|
||||
[deck, user]
|
||||
);
|
||||
const [inserted] = insert.rows;
|
||||
return inserted.id;
|
||||
});
|
||||
|
||||
public getDeck: (id: number, user?: string) => Promise<Deck.Deck> = async (
|
||||
id,
|
||||
user = undefined
|
||||
) =>
|
||||
await this.withClient(async (client) => {
|
||||
const meta = await (user === undefined
|
||||
? client.query(
|
||||
`
|
||||
SELECT users.name as author, decks.deck, decks.version
|
||||
FROM manydecks.decks INNER JOIN manydecks.users ON users.id = decks.author
|
||||
WHERE decks.id = $1;
|
||||
`,
|
||||
[id]
|
||||
)
|
||||
: client.query(
|
||||
`
|
||||
SELECT users.name as author, decks.deck, decks.version
|
||||
FROM manydecks.decks INNER JOIN manydecks.users ON users.id = decks.author
|
||||
WHERE decks.id = $1 AND decks.author = $2;
|
||||
`,
|
||||
[id, user]
|
||||
));
|
||||
if (meta.rowCount === 0) {
|
||||
throw new Errors.DeckNotFound();
|
||||
}
|
||||
const [metaRow] = meta.rows;
|
||||
return {
|
||||
...metaRow.deck,
|
||||
author: metaRow.author,
|
||||
version: metaRow.version,
|
||||
};
|
||||
});
|
||||
|
||||
public getDecks: (user: string) => Promise<Deck.Deck[]> = async (user) =>
|
||||
await this.withClient(async (client) => {
|
||||
const decks = await client.query(
|
||||
`
|
||||
SELECT users.name as author, decks.deck, decks.version
|
||||
FROM manydecks.decks INNER JOIN manydecks.users ON users.id = decks.author
|
||||
WHERE decks.author = $1;
|
||||
`,
|
||||
[user]
|
||||
);
|
||||
const results: Deck.Deck[] = [];
|
||||
for (const deck of decks.rows) {
|
||||
results.push({
|
||||
...deck.deck,
|
||||
author: deck.author,
|
||||
version: deck.version,
|
||||
});
|
||||
}
|
||||
return results;
|
||||
});
|
||||
|
||||
public getSummary: (id: number) => Promise<Deck.Summary> = async (id) =>
|
||||
await this.withClient(async (client) => {
|
||||
const meta = await client.query(
|
||||
`
|
||||
SELECT name, author, language, calls, responses, version
|
||||
FROM manydecks.summaries WHERE summaries.id = $1;
|
||||
`,
|
||||
[id]
|
||||
);
|
||||
if (meta.rowCount === 0) {
|
||||
throw new Errors.DeckNotFound();
|
||||
}
|
||||
const [metaRow] = meta.rows;
|
||||
return {
|
||||
details: {
|
||||
name: metaRow.name,
|
||||
author: metaRow.author,
|
||||
language: metaRow.language,
|
||||
},
|
||||
calls: metaRow.calls,
|
||||
responses: metaRow.responses,
|
||||
version: metaRow.version,
|
||||
};
|
||||
});
|
||||
|
||||
public getSummariesForUser: (
|
||||
user: string
|
||||
) => Promise<Deck.SummaryAndCode[]> = async (user) =>
|
||||
await this.withClient(async (client) => {
|
||||
const result = await client.query(
|
||||
`
|
||||
SELECT id, name, author, language, calls, responses, version
|
||||
FROM manydecks.summaries WHERE summaries.author_id = $1;
|
||||
`,
|
||||
[user]
|
||||
);
|
||||
const summaries = [];
|
||||
for (const deck of result.rows) {
|
||||
const code = Code.encode(deck.id);
|
||||
summaries.push({
|
||||
code,
|
||||
summary: {
|
||||
details: {
|
||||
name: deck.name,
|
||||
author: deck.author,
|
||||
language: deck.language,
|
||||
},
|
||||
calls: deck.calls,
|
||||
responses: deck.responses,
|
||||
version: deck.version,
|
||||
},
|
||||
});
|
||||
}
|
||||
return summaries;
|
||||
});
|
||||
|
||||
public updateDeck: (
|
||||
id: number,
|
||||
user: string,
|
||||
patch: Patch.Operation[]
|
||||
) => Promise<Deck.Deck> = async (id, user, patch) =>
|
||||
await this.withClient(async (client) => {
|
||||
const deck = await this.getDeck(id, user);
|
||||
try {
|
||||
JsonPatch.applyPatch(deck, patch);
|
||||
} catch (error) {
|
||||
if (
|
||||
error instanceof JsonPatch.JsonPatchError &&
|
||||
error.name === "TEST_OPERATION_FAILED"
|
||||
) {
|
||||
throw new Errors.PatchTestFailed();
|
||||
} else {
|
||||
throw new Errors.BadPatch();
|
||||
}
|
||||
}
|
||||
let updated;
|
||||
try {
|
||||
updated = Deck.validate({
|
||||
...deck,
|
||||
author: undefined,
|
||||
version: undefined,
|
||||
});
|
||||
} catch (error) {
|
||||
throw new Errors.BadPatch();
|
||||
}
|
||||
await client.query(
|
||||
`
|
||||
UPDATE manydecks.decks SET deck = $1 WHERE id = $2;
|
||||
`,
|
||||
[updated, id]
|
||||
);
|
||||
return deck;
|
||||
});
|
||||
|
||||
public deleteDeck: (id: number, user: string) => Promise<void> = async (
|
||||
id,
|
||||
user
|
||||
) =>
|
||||
await this.withClient(async (client) => {
|
||||
const result = await client.query(
|
||||
`DELETE FROM manydecks.decks WHERE id = $1 AND author = $2`,
|
||||
[id, user]
|
||||
);
|
||||
if (result.rowCount === 0) {
|
||||
throw new Errors.DeckNotFound();
|
||||
}
|
||||
});
|
||||
|
||||
private async withClient<Result>(
|
||||
f: (client: Pg.PoolClient) => Promise<Result>
|
||||
): Promise<Result> {
|
||||
const client = await this.pool.connect();
|
||||
try {
|
||||
return await f(client);
|
||||
} finally {
|
||||
client.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import * as uuid from "uuid";
|
||||
|
||||
export type Id = string;
|
||||
|
||||
export const id: () => Id = uuid.v4;
|
||||
|
||||
export interface User {
|
||||
id: Id;
|
||||
name: string;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import { default as Jwt } from "jsonwebtoken";
|
||||
import * as User from "../user";
|
||||
import * as Errors from "../errors";
|
||||
|
||||
export interface Config {
|
||||
issuer: string;
|
||||
secret: string;
|
||||
algorithm: Jwt.Algorithm;
|
||||
historicAlgorithms: Jwt.Algorithm[];
|
||||
expiresIn: string;
|
||||
}
|
||||
|
||||
export interface Claims {
|
||||
sub: User.Id;
|
||||
}
|
||||
|
||||
export class Auth {
|
||||
private readonly config: Config;
|
||||
|
||||
public constructor(config: Config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public sign(claims: Claims): string {
|
||||
const { secret, algorithm, issuer, expiresIn } = this.config;
|
||||
return Jwt.sign(claims, secret, { algorithm, issuer, expiresIn });
|
||||
}
|
||||
|
||||
public validate(token: string): Claims {
|
||||
const { secret, algorithm, historicAlgorithms, issuer } = this.config;
|
||||
try {
|
||||
return Jwt.verify(token, secret, {
|
||||
algorithms: [algorithm, ...historicAlgorithms],
|
||||
issuer,
|
||||
}) as Claims;
|
||||
} catch (error) {
|
||||
throw new Errors.AuthFailure();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"include": ["./src/ts/**/*"],
|
||||
"compilerOptions": {
|
||||
"target": "esnext",
|
||||
"module": "esnext",
|
||||
"sourceMap": true,
|
||||
"outDir": "./dist",
|
||||
"incremental": true,
|
||||
"removeComments": true,
|
||||
"resolveJsonModule": true,
|
||||
"strict": true,
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictBindCallApply": true,
|
||||
"strictPropertyInitialization": true,
|
||||
"noImplicitThis": true,
|
||||
"alwaysStrict": true,
|
||||
"noImplicitReturns": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"moduleResolution": "node",
|
||||
"allowSyntheticDefaultImports": true
|
||||
}
|
||||
}
|
||||