Commit 7b12e9ca authored by MrMan's avatar MrMan

Merge branch 'part-5-add-parceljs'

parents 26ae1975 b66c090d
/* global document, m, System */
import m from "./static/vendor/mithril/1.1.6/mithril.min";
import EmailSvc from "./services/email.js";
import MainLayout from "./components/main-layout";
import WithRouteTriggeredLoader from "./components/with-route-triggered-loader";
import InboxMail from "./components/inbox-mail";
let StarredMail;
// Set up the app
m.route(document.body, "/inbox", {
"/inbox": {
render: function() {
return m(MainLayout, m(WithRouteTriggeredLoader, {
title: "Loading inbox...",
// This function provides the data
loadFn: function() { return EmailSvc.getEmails(); },
// This function provides the component to WithRouteTriggeredLoader
childFn: function(data) { return m(InboxMail, {emails: data}); }
}));
}
},
"/starred": {
onmatch: function() {
// Load starred mail *when we need it*
return import("./components/starred-mail")
.then((mod) => StarredMail = mod.default);
},
},
"/draft": {
onmatch: function() {
return import("./components/draft-mail")
.then(({default: DraftMail}) => DraftMail);
}
},
"/important": {
onmatch: function() {
return import("./components/important-mail")
.then(({default: ImportantMail}) => ImportantMail);
}
},
System.register([
"./services/email.js",
"./components/main-layout.js",
"./components/with-route-triggered-loader.js",
"./components/inbox-mail.js",
], function(exportModule, moduleCtx) {
return {
execute: function() {
Promise.all([
moduleCtx.import("./services/email.js"),
moduleCtx.import("./components/main-layout.js"),
moduleCtx.import("./components/with-route-triggered-loader.js"),
moduleCtx.import("./components/inbox-mail.js"),
])
.then(function(deps) {
var EmailSvc = deps.shift().service;
var MainLayout = deps.shift().component;
var WithRouteTriggeredLoader = deps.shift().component;
var InboxMail = deps.shift().component;
// Set up the app
m.route(document.body, "/inbox", {
"/inbox": {
render: function() {
return m(MainLayout, m(WithRouteTriggeredLoader, {
title: "Loading inbox...",
// This function provides the data
loadFn: function() { return EmailSvc.getEmails(); },
// This function provides the component to WithRouteTriggeredLoader
childFn: function(data) { return m(InboxMail, {emails: data}); }
}));
}
},
"/starred": {
render: function() {
// Load starred mail *when we need it*
return moduleCtx
.import("./components/starred-mail.js")
.then(function(StarredMailModule) {
var StarredMail = StarredMailModule.component;
return m(MainLayout, m(WithRouteTriggeredLoader, {
title: "Loading starred emails...",
// This function provides the data
loadFn: function() { return EmailSvc.getEmails(); },
// This function provides the component to WithRouteTriggeredLoader
childFn: function(data) { return m(StarredMail, {emails: data}); }
}));
});
}
},
"/draft": {
render: function() {
return moduleCtx
.import("./components/draft-mail.js")
.then(function(DraftMailModule) {
DraftMail = DraftMailModule.component;
return m(MainLayout, m(WithRouteTriggeredLoader, {
title: "Loading draft emails...",
// This function provides the data
loadFn: function() { return EmailSvc.getEmails(); },
// This function provides the component to WithRouteTriggeredLoader
childFn: function(data) { return m(DraftMail, {emails: data}); }
}));
});
}
},
"/important": {
render: function() {
return moduleCtx
.import("./components/important-mail.js")
.then(function(ImportantMailModule) {
var ImportantMail = ImportantMailModule.component;
return m(MainLayout, m(WithRouteTriggeredLoader, {
title: "Loading important emails...",
// This function provides the data
loadFn: function() { return EmailSvc.getEmails(); },
// This function provides the component to WithRouteTriggeredLoader
childFn: function(data) { return m(ImportantMail, {emails: data}); }
}));
});
}
},
});
// This module exports nothing, just runs once
exportModule({});
});
}, // /execute
};
});
/* global System */
System.register([
"./rhs-header.js",
"./mail-page-subnav.js",
"./email-list.js",
], function(exportModule, moduleCtx) {
return {
execute: function() {
import m from "../static/vendor/mithril/1.1.6/mithril.min";
Promise.all([
moduleCtx.import("./rhs-header.js"),
moduleCtx.import("./mail-page-subnav.js"),
moduleCtx.import("./email-list.js"),
])
.then(function(deps) {
var RHSHeader = deps.shift().component;
var MailPageSubNav = deps.shift().component;
var EmailList = deps.shift().component;
import EmailSvc from "../services/email";
var DraftMail = {
view: function(vnode) {
var newCount = vnode.attrs.newCount;
import RHSHeader from "./rhs-header";
import MailPageSubNav from "./mail-page-subnav";
import EmailList from "./email-list";
import MainLayout from "./main-layout";
import WithRouteTriggeredLoader from "./with-route-triggered-loader";
return m(".component.draft-rhs", [
// Colored header
m(RHSHeader, {class: "draft-gray-bg white-fg", title: "Draft", newCount: newCount}),
const DraftMail = {
view: function(vnode) {
const newCount = vnode.attrs.newCount;
// Container with buttons
m(MailPageSubNav),
return m(MainLayout,
m(WithRouteTriggeredLoader, {
title: "Loading draft emails...",
// This function provides the data
loadFn: function() { return EmailSvc.getEmails(); },
// This function provides the component to WithRouteTriggeredLoader
childFn: (data) => m(".component.draft-rhs", [
// Colored header
m(RHSHeader, {class: "draft-gray-bg white-fg", title: "Draft", newCount: newCount}),
// EmailList
m(EmailList, {emails: vnode.attrs.emails}),
]);
}
};
// Container with buttons
m(MailPageSubNav),
exportModule({component: DraftMail});
});
// EmailList
m(EmailList, {emails: data}),
])
})
);
},
};
},
};
});
export default DraftMail;
/* global System */
System.register([
"../services/email.js",
], function(exportModule, moduleCtx) {
return {
execute: function() {
Promise.all([
moduleCtx.import("../services/email.js",)
]).then(function(deps) {
var EmailSvc = deps.shift().service;
import m from "../static/vendor/mithril/1.1.6/mithril.min.js";
import EmailSvc from "../services/email.js";
var ELLIPSIS_CHAR_LIMIT = 60;
const ELLIPSIS_CHAR_LIMIT = 60;
var EmailListItem = {
view: function(vnode) {
var email = vnode.attrs.email;
var textContent = email.text || "";
var formattedSendDate = email.sendDate.toLocaleString();
const EmailListItem = {
view: function(vnode) {
const email = vnode.attrs.email;
const textContent = email.text || "";
const formattedSendDate = email.sendDate.toLocaleString();
var isSelected = EmailSvc.getEmailSelectedStatusById(email.id);
var isChecked = EmailSvc.getEmailCheckedStatusById(email.id);
const isSelected = EmailSvc.getEmailSelectedStatusById(email.id);
const isChecked = EmailSvc.getEmailCheckedStatusById(email.id);
var additionalClasses = [];
if (isSelected) { additionalClasses.push("selected"); }
let additionalClasses = [];
if (isSelected) { additionalClasses.push("selected"); }
return m(
".component.email-list-item.clickable",
{
class: additionalClasses.join(" "),
onclick: function() { EmailSvc.toggleSelectionStatusById(email.id); }
},
[
m(".header", [
m(".lhs", [
m("input[type=checkbox]", {
checked: isChecked,
onclick: function() { EmailSvc.toggleCheckedStatusById(email.id); }
}),
m("span.sm-margin-left.sender", email.from.name),
m("span.sm-margin-left.tag", email.label),
]),
return m(
".component.email-list-item.clickable",
{
class: additionalClasses.join(" "),
onclick: () => EmailSvc.toggleSelectionStatusById(email.id),
},
[
m(".header", [
m(".lhs", [
m("input[type=checkbox]", {
checked: isChecked,
onclick: () => EmailSvc.toggleCheckedStatusById(email.id),
}),
m("span.sm-margin-left.sender", email.from.name),
m("span.sm-margin-left.tag", email.label),
]),
m(".rhs", [
m(".date", formattedSendDate)
])
]),
m(".rhs", [
m(".date", formattedSendDate)
])
]),
m(".blurb.md-margin-top", [
m("p.subject", email.subject),
// This is not a great way to do ellipsis but... it'll work for the demo.
m("p.body-preview", textContent.substring(0, ELLIPSIS_CHAR_LIMIT) + "..."),
]),
m(".blurb.md-margin-top", [
m("p.subject", email.subject),
// This is not a great way to do ellipsis but... it'll work for the demo.
m("p.body-preview", textContent.substring(0, ELLIPSIS_CHAR_LIMIT) + "..."),
]),
]);
}
};
]);
}
};
var EmailList = {
oninit: function() {
this.selectedEmails = {};
},
const EmailList = {
oninit: function() {
this.selectedEmails = {};
},
view: function(vnode) {
var emails = vnode.attrs.emails || [];
return m(".component.email-list", emails.map(function(email) {
return m(EmailListItem, {
email: email,
onEmailSelect: function(email) { this.selectedEmails[email.id] = true; },
});
}));
}
};
exportModule({component: EmailList});
view: function(vnode) {
const emails = vnode.attrs.emails || [];
return m(".component.email-list", emails.map(function(email) {
return m(EmailListItem, {
email: email,
onEmailSelect: (email) => this.selectedEmails[email.id] = true,
});
}));
}
};
},
};
});
export default EmailList;
/* global System */
System.register([
"./rhs-header.js",
"./mail-page-subnav.js",
"./email-list.js",
], function(exportModule, moduleCtx) {
return {
execute: function() {
import m from "../static/vendor/mithril/1.1.6/mithril.min";
Promise.all([
moduleCtx.import("./rhs-header.js"),
moduleCtx.import("./mail-page-subnav.js"),
moduleCtx.import("./email-list.js"),
])
.then(function(deps) {
var RHSHeader = deps.shift().component;
var MailPageSubNav = deps.shift().component;
var EmailList = deps.shift().component;
import EmailSvc from "../services/email";
var ImportantMail = {
view: function(vnode) {
var newCount = vnode.attrs.newCount;
import RHSHeader from "./rhs-header";
import MailPageSubNav from "./mail-page-subnav";
import EmailList from "./email-list";
import MainLayout from "./main-layout";
import WithRouteTriggeredLoader from "./with-route-triggered-loader";
return m(".component.important-rhs", [
// Colored header
m(RHSHeader, {class: "important-red-bg white-fg", title: "Important", newCount: newCount}),
const ImportantMail = {
view: function(vnode) {
const newCount = vnode.attrs.newCount;
// Container with buttons
m(MailPageSubNav),
return m(MainLayout,
m(WithRouteTriggeredLoader, {
title: "Loading important emails...",
// This function provides the data
loadFn: function() { return EmailSvc.getEmails(); },
// This function provides the component to WithRouteTriggeredLoader
childFn: (data) => m(".component.important-rhs", [
// Colored header
m(RHSHeader, {class: "important-red-bg white-fg", title: "Important", newCount: newCount}),
// EmailList
m(EmailList, {emails: vnode.attrs.emails}),
]);
}
};
// Container with buttons
m(MailPageSubNav),
exportModule({component: ImportantMail});
});
// EmailList
m(EmailList, {emails: data}),
])
})
);
}
};
},
};
});
export default ImportantMail;
/* global System */
System.register([
"./rhs-header.js",
"./mail-page-subnav.js",
"./email-list.js",
], function(exportModule, moduleCtx) {
return {
execute: function() {
import m from "../static/vendor/mithril/1.1.6/mithril.min";
import RHSHeader from "./rhs-header";
import MailPageSubNav from "./mail-page-subnav";
import EmailList from "./email-list";
Promise.all([
moduleCtx.import("./rhs-header.js"),
moduleCtx.import("./mail-page-subnav.js"),
moduleCtx.import("./email-list.js"),
])
.then(function(deps) {
var RHSHeader = deps.shift().component;
var MailPageSubNav = deps.shift().component;
var EmailList = deps.shift().component;
const InboxMail = {
view: function(vnode) {
const newCount = vnode.attrs.newCount;
const emails = vnode.attrs.emails;
var InboxMail = {
view: function(vnode) {
var newCount = vnode.attrs.newCount;
var emails = vnode.attrs.emails;
return m(".component.inbox-rhs", [
// Colored header
m(RHSHeader, {class: "inbox-blue-bg white-fg", title: "Inbox", newCount: newCount}),
return m(".component.inbox-rhs", [
// Colored header
m(RHSHeader, {class: "inbox-blue-bg white-fg", title: "Inbox", newCount: newCount}),
// Container with buttons
m(MailPageSubNav),
// Container with buttons
m(MailPageSubNav),
// EmailList
m(EmailList, {emails: vnode.attrs.emails}),
]);
}
};
// EmailList
m(EmailList, {emails: vnode.attrs.emails}),
]);
}
};
exportModule({component: InboxMail});
});
},
};
});
export default InboxMail;
This diff is collapsed.
System.register([
"../services/email.js",
], function(exportModule, moduleCtx) {
return {
execute: function() {
Promise.all([
moduleCtx.import("../services/email.js",)
]).then(function(deps) {
var EmailSvc = deps.shift().service;
var MultiSelectCheckbox = {
view: function(vnode) {
var allEmailsChecked = vnode.attrs.allEmailsChecked;
var oneOrMoreEmailsChecked = vnode.attrs.oneOrMoreEmailsChecked;
var dropdownContentClasses = [];
var dropdownContentHidden = "dropdownContentHidden" in vnode.attrs ? vnode.attrs.dropdownContentHidden : true;
if (dropdownContentHidden) { dropdownContentClasses.push("hidden"); }
var selectionIconSrc = "static/images/icons/square.svg";
if (oneOrMoreEmailsChecked) { selectionIconSrc = "static/images/icons/minus-square.svg"; }
if (allEmailsChecked) { selectionIconSrc = "static/images/icons/check-square.svg"; }
var selectionText = "Select All";
if (oneOrMoreEmailsChecked) { selectionText = "Clear Selection"; }
if (allEmailsChecked) { selectionText = "Unselect All"; }
var clickHandler = function() { EmailSvc.checkAllEmails(); };
if (allEmailsChecked || oneOrMoreEmailsChecked) { clickHandler = function() { EmailSvc.clearCheckedEmails(); }; }
return m(
"span.component.multi-select-checkbox.gray-boxed.clickable",
{onclick: clickHandler},
[
m("span", [
m("img.icon", {src: selectionIconSrc}),
m("span.xs-margin-left", selectionText),
]),
]);
}
};
var ButtonGroup = {
view: function(vnode) {
return m("span.component.button-group", {class: vnode.attrs.class}, vnode.children);
}
};
var DropDownButton = {
view: function(vnode) {
var title = vnode.attrs.title || "Button";
return m("button.component.drop-down-button.gray-boxed.clickable", [
m("span", title),
m("img.xs-margin-left.icon", {src: "static/images/icons/chevron-down.svg"}),
]);
}
};
var PaginationControls = {
view: function(vnode) {
var title = vnode.attrs.title || "Button";
var lowerBound = 0;
var upperBound = 50;
var boundStatement = lowerBound + " - " + upperBound;
var total = 100;
return m(".component.pagination-controls", [
m("strong", boundStatement),
m("span", " of "),
m("strong", total),
m("img.xs-margin-left.icon-lg.gray-boxed.valign-mid", {src: "static/images/icons/chevron-left.svg"}),
m("img.xs-margin-left.icon-lg.gray-boxed.valign-mid", {src: "static/images/icons/chevron-right.svg"}),
]);
}
};
var MailPageSubNav = {
view: function(vnode) {
var allEmailsChecked = EmailSvc.allEmailsChecked();
var oneOrMoreEmailsChecked = EmailSvc.oneOrMoreEmailsChecked();
// Container with buttons
return m(".component.mail-page-subnav", [
m(".lhs", [
m(MultiSelectCheckbox, {
allEmailsChecked: allEmailsChecked,
oneOrMoreEmailsChecked: oneOrMoreEmailsChecked,
}),
m(ButtonGroup, {class: "sm-margin-left"}, [
m("button.clickable", "Archive"),
m("button.clickable", "Spam"),
m("button.clickable", "Delete"),
]),
m(ButtonGroup, {class: "sm-margin-left"}, [
m(DropDownButton, {title: "Move to"}),
m(DropDownButton, {title: "Label"}),
]),
]),
m(".rhs", [
m(PaginationControls)
]),
]);
},
};
exportModule({component: MailPageSubNav});
});
},
};
});
import m from "../static/vendor/mithril/1.1.6/mithril.min.js";
import EmailSvc from "../services/email.js";
import SquareIcon from "../static/images/icons/square.svg";
import MinusSquareIcon from "../static/images/icons/minus-square.svg";
import CheckSquareIcon from "../static/images/icons/check-square.svg";
import ChevronDownIcon from "../static/images/icons/chevron-down.svg";
import ChevronLeftIcon from "../static/images/icons/chevron-left.svg";
import ChevronRightIcon from "../static/images/icons/chevron-right.svg";
const MultiSelectCheckbox = {
view: function(vnode) {
const allEmailsChecked = vnode.attrs.allEmailsChecked;
const oneOrMoreEmailsChecked = vnode.attrs.oneOrMoreEmailsChecked;
const dropdownContentClasses = [];
const dropdownContentHidden = "dropdownContentHidden" in vnode.attrs ? vnode.attrs.dropdownContentHidden : true;
if (dropdownContentHidden) { dropdownContentClasses.push("hidden"); }
let selectionIconSrc = SquareIcon;
if (oneOrMoreEmailsChecked) { selectionIconSrc = MinusSquareIcon; }
if (allEmailsChecked) { selectionIconSrc = CheckSquareIcon; }
let selectionText = "Select All";
if (oneOrMoreEmailsChecked) { selectionText = "Clear Selection"; }
if (allEmailsChecked) { selectionText = "Unselect All"; }
let clickHandler = function() { EmailSvc.checkAllEmails(); };
if (allEmailsChecked || oneOrMoreEmailsChecked) { clickHandler = function() { EmailSvc.clearCheckedEmails(); }; }
return m(
"span.component.multi-select-checkbox.gray-boxed.clickable",
{onclick: clickHandler},
[
m("span", [
m("img.icon", {src: selectionIconSrc}),
m("span.xs-margin-left", selectionText),
]),
]);
}
};
const ButtonGroup = {
view: function(vnode) {
return m("span.component.button-group", {class: vnode.attrs.class}, vnode.children);
}
};
const DropDownButton = {
view: function(vnode) {
const title = vnode.attrs.title || "Button";
return m("button.component.drop-down-button.gray-boxed.clickable", [
m("span", title),
m("img.xs-margin-left.icon", {src: ChevronDownIcon}),
]);
}
};
const PaginationControls = {
view: function(vnode) {
const title = vnode.attrs.title || "Button";
const lowerBound = 0;
const upperBound = 50;
const boundStatement = lowerBound + " - " + upperBound;
const total = 100;
return m(".component.pagination-controls", [
m("strong", boundStatement),
m("span", " of "),
m("strong", total),
m("img.xs-margin-left.icon-lg.gray-boxed.valign-mid", {src: ChevronLeftIcon}),
m("img.xs-margin-left.icon-lg.gray-boxed.valign-mid", {src: ChevronRightIcon}),
]);
}
};
const MailPageSubNav = {
view: function(vnode) {
const allEmailsChecked = EmailSvc.allEmailsChecked();
const oneOrMoreEmailsChecked = EmailSvc.oneOrMoreEmailsChecked();
// Container with buttons
return m(".component.mail-page-subnav", [
m(".lhs", [
m(MultiSelectCheckbox, {
allEmailsChecked: allEmailsChecked,
oneOrMoreEmailsChecked: oneOrMoreEmailsChecked,
}),
m(ButtonGroup, {class: "sm-margin-left"}, [
m("button.clickable", "Archive"),
m("button.clickable", "Spam"),
m("button.clickable", "Delete"),
]),
m(ButtonGroup, {class: "sm-margin-left"}, [
m(DropDownButton, {title: "Move to"}),
m(DropDownButton, {title: "Label"}),
]),
]),