Commit 3f05a4f7 authored by MrMan's avatar MrMan

Work through parcel integration

parent 26ae1975
/* 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";
// 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(({default: StarredMail}) => StarredMail);
},
},
"/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";
import RHSHeader from "./rhs-header";
import MailPageSubNav from "./mail-page-subnav";
import EmailList from "./email-list";
import MainLayout from "./main-layout";
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 DraftMail = {
view: function(vnode) {
const newCount = vnode.attrs.newCount;
var DraftMail = {
view: function(vnode) {
var newCount = vnode.attrs.newCount;
return m(MainLayout,
m(".component.draft-rhs", [
// Colored header
m(RHSHeader, {class: "draft-gray-bg white-fg", title: "Draft", newCount: newCount}),
return m(".component.draft-rhs", [
// Colored header
m(RHSHeader, {class: "draft-gray-bg white-fg", title: "Draft", 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: DraftMail});
});
},
};
});
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";
import RHSHeader from "./rhs-header";
import MailPageSubNav from "./mail-page-subnav";
import EmailList from "./email-list";
import MainLayout from "./main-layout";
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 ImportantMail = {
view: function(vnode) {
const newCount = vnode.attrs.newCount;
var ImportantMail = {
view: function(vnode) {
var newCount = vnode.attrs.newCount;
return m(MainLayout,
m(".component.important-rhs", [
// Colored header
m(RHSHeader, {class: "important-red-bg white-fg", title: "Important", newCount: newCount}),
return m(".component.important-rhs", [
// Colored header
m(RHSHeader, {class: "important-red-bg white-fg", title: "Important", 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: ImportantMail});
});
},
};
});
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;
/* global m, System */
System.register([], function(exportModule, moduleCtx) {
return {
execute: function() {
var LHS_NAV_ITEMS = [
{
title: "Inbox",
iconImgSrc: "static/images/icons/inbox-white.svg",
badgeCSSBgColor: "#2285c6",
badgeContent: 2,
route: "/inbox",
},
{
title: "Starred",
iconImgSrc: "static/images/icons/star-full-white.svg",
route: "/starred",
},
{
title: "Draft",
iconImgSrc: "static/images/icons/file-line-white.svg",
route: "/draft",
},
{
title: "Important",
iconImgSrc: "static/images/icons/exclamation-triangle-white.svg",
route: "/important",
},
];
var LHS_LABEL_ITEMS = [
{
title: "Work",
badgeCSSBgColor: "#02bfc0",
badgeEmptySquare: true,
},
{
title: "Private",
badgeCSSBgColor: "#f9d47b",
badgeEmptySquare: true,
},
{
title: "Priority",
badgeCSSBgColor: "#9391e5",
badgeEmptySquare: true,
},
];
var HeaderButton = {
view: function(vnode) {
var text = vnode.attrs.title || "Compose Mail";
var iconName = vnode.attrs.iconName || "pencil-white.svg";
var iconPrefix = "static/images/icons/";
return m("button", {class: "component header-button"}, [
m("span", text),
m("img", {class: "sm-margin-left icon", src: iconPrefix + iconName }),
]);
}
};
var LHSNavHeader = {
view: function() {
return m("header", [
m(HeaderButton),
]);
}
};
var Badge = {
view: function(vnode) {
var styles = [];
var content = vnode.attrs.content || "";
var bgColor = vnode.attrs.cssBgColor || "gray";
var color = vnode.attrs.cssBgColor || "white";
var emptySquare = vnode.attrs.emptySquare;
var classes = ["component", "badge"];
styles.push("background-color:" + vnode.attrs.cssBgColor);
styles.push("color:" + vnode.attrs.cssColor);
var combinedStyles = styles.join(";");
if (emptySquare) { classes.push("empty-square"); }
return m("div", {class: classes.join(" "), style: combinedStyles}, content);
}
};
var NavItem = {
view: function(vnode) {
var data = vnode.attrs.data || {};
var title = data.title || "Placeholder";
var iconImgSrc = data.iconImgSrc;
var badgeContent = data.badgeContent || 0;
var badgeCSSBgColor = data.badgeCSSBgColor;
var badgeEmptySquare = data.badgeEmptySquare;
var children = [title];
var classes = ["component", "nav-item", "md-padding-horiz"];
if (data.selected) { classes.push("selected"); }
// If there's an icon specified display it
if (iconImgSrc) {
children.unshift(m("img", {class: "sm-margin-left sm-margin-right icon", src: iconImgSrc}));
} else {
children.unshift(m("div", {class: "placeholder-1em"}));
}
// If badgeColor and badgeContent are specified then show a badge
if (badgeEmptySquare && badgeCSSBgColor || badgeContent && badgeCSSBgColor) {
children.push(m("div", {class: "badge-container float-right"}, [
m(Badge, {
class: "float-right",
cssBgColor: badgeCSSBgColor,
content: badgeContent,
emptySquare: badgeEmptySquare
})
]));
}
return m("li.clickable", {
class: classes.join(" "),
onclick: function(e) {
// Navigate to the appropriate link for this
m.route.set(data.route);
},
}, children);
}
};
var NavItemListing = {
view: function(vnode) {
var navItems = vnode.attrs.items || [];
var children = navItems.map(function(i) {
return m(NavItem, {data: i});
});
return m("ul", {class: "component nav-item-listing"}, children);
}
};
var LHSNavPageList = {
view: function() {
// Mark the nav items with the correct selected property
var currentPath = m.route.get();
var navItems = LHS_NAV_ITEMS.map(function(item) {
item.selected = currentPath === item.route;
return item;
});
return m(NavItemListing, {items: navItems});
}
};
var LHSNavLabelList = {
view: function() {
var labelItems = LHS_LABEL_ITEMS;
return m(NavItemListing, {items: labelItems});
}
};
var LHSNav = {
view: function() {
return m("div", {class: "component lhs-nav"}, [
m(LHSNavHeader),
m(LHSNavPageList),
m("hr"),
m("h2", {class: "slim-text sm-padding-horiz"}, "Labels"),
m(LHSNavLabelList),
m("hr"),
]);
}
};
// SystemJS export
exportModule({component: LHSNav});
},
};
});
import m from "../static/vendor/mithril/1.1.6/mithril.min.js";
var LHS_NAV_ITEMS = [
{
title: "Inbox",
iconImgSrc: "static/images/icons/inbox-white.svg",
badgeCSSBgColor: "#2285c6",
badgeContent: 2,
route: "/inbox",
},
{
title: "Starred",
iconImgSrc: "static/images/icons/star-full-white.svg",
route: "/starred",
},
{
title: "Draft",
iconImgSrc: "static/images/icons/file-line-white.svg",
route: "/draft",
},
{
title: "Important",
iconImgSrc: "static/images/icons/exclamation-triangle-white.svg",
route: "/important",
},
];
var LHS_LABEL_ITEMS = [
{
title: "Work",
badgeCSSBgColor: "#02bfc0",
badgeEmptySquare: true,
},
{
title: "Private",
badgeCSSBgColor: "#f9d47b",
badgeEmptySquare: true,
},
{
title: "Priority",
badgeCSSBgColor: "#9391e5",
badgeEmptySquare: true,
},
];
var HeaderButton = {
view: function(vnode) {
var text = vnode.attrs.title || "Compose Mail";
var iconName = vnode.attrs.iconName || "pencil-white.svg";
var iconPrefix = "static/images/icons/";
return m("button", {class: "component header-button"}, [
m("span", text),
m("img", {class: "sm-margin-left icon", src: iconPrefix + iconName }),