Commit 5db072c3 authored by MrMan's avatar MrMan

all components in their own files

parent 4e56173b
This diff is collapsed.
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 ButtonGroup = {
view: function(vnode) {
return m("span.component.button-group", {class: vnode.attrs.class}, vnode.children);
}
};
var DraftMail = {
view: function(vnode) {
var newCount = vnode.attrs.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),
// EmailList
m(EmailList, {emails: vnode.attrs.emails}),
]);
}
};
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 EmailListItem = {
view: function(vnode) {
var email = vnode.attrs.email;
var textContent = email.text || "";
var formattedSendDate = email.sendDate.toLocaleString();
var isSelected = EMAIL_SVC.getEmailSelectedStatusById(email.id);
var isChecked = EMAIL_SVC.getEmailCheckedStatusById(email.id);
var additionalClasses = [];
if (isSelected) { additionalClasses.push("selected"); }
return m(
".component.email-list-item.clickable",
{
class: additionalClasses.join(" "),
onclick: function() { EMAIL_SVC.toggleSelectionStatusById(email.id); }
},
[
m(".header", [
m(".lhs", [
m("input[type=checkbox]", {
checked: isChecked,
onclick: function() { EMAIL_SVC.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(".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 = {};
},
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; },
});
}));
}
};
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 ImportantMail = {
view: function(vnode) {
var newCount = vnode.attrs.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),
// EmailList
m(EmailList, {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}),
// Container with buttons
m(MailPageSubNav),
// EmailList
m(EmailList, {emails: vnode.attrs.emails}),
]);
}
};
var LHSNavHeader = {
view: function() {
return m("header", [
m(HeaderButton),
]);
}
};
var LHSNavLabelList = {
view: function() {
var labelItems = LHS_LABEL_ITEMS;
return m(NavItemListing, {items: labelItems});
}
};
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 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"),
]);
}
};
var LoadingIndicator = {
view: function(vnode) {
var title = vnode.attrs.title || "Loading...";
return m(".component.loading-indicator", [
m("img.icon.loading-icon", {src: "static/images/icons/loader-gray.svg"}),
m(".title", title),
]);
},
};
var MailPageSubNav = {
view: function(vnode) {
var allEmailsChecked = EMAIL_SVC.allEmailsChecked();
var oneOrMoreEmailsChecked = EMAIL_SVC.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)
]),
]);
},
};
var MainLayout = {
view: function(vnode) {
return m(".component.app-page.important-page", [
m(LHSNav),
vnode.children,
]);
},
};
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() { EMAIL_SVC.checkAllEmails(); };
if (allEmailsChecked || oneOrMoreEmailsChecked) { clickHandler = function() { EMAIL_SVC.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 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 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 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 RHSHeader = {
view: function(vnode) {
var title = vnode.attrs.title || "Title";
var bgColor = vnode.attrs.bgColor || "#2285c6";
var newCount = vnode.attrs.newCount;
return m("div.component.rhs-header.flex", {class: vnode.attrs.class}, [
m(".title-container", [
m("span.title", title),
newCount ? m("span.new-count", "(" + newCount + ")"): undefined,
]),
m(".controls", [
m("input.search-box[type='text'][placeholder='Search']"),
m("img.sm-margin-left.icon", {src: "static/images/icons/settings-white.svg"}),
m("img.sm-margin-left.avatar", {src: "static/images/example-avatar.jpg"}),
])
]);
}
};
var StarredMail = {
view: function(vnode) {
var newCount = vnode.attrs.newCount;
return m(".component.starred-rhs", [
// Colored header
m(RHSHeader, {class: "starred-orange-bg white-fg", title: "Starred", newCount: newCount}),
// Container with buttons
m(MailPageSubNav),
// EmailList
m(EmailList, {emails: vnode.attrs.emails}),
]);
}
};
var WithRouteTriggeredLoader = {
oninit: function(vnode) {
this.loadFn = vnode.attrs.loadFn;
this.requestInFlight = false;
this.refetchOnUpdate = true;
if ("refetchOnUpdate" in vnode.attrs) { this.refetchOnUpdate = vnode.attrs.refetchOnUpdate; }
// Trigger initial fetch
this.fetchAndRedraw();
},
fetchAndRedraw: function() {
this.loaded = false;
this.loadedData = null;
// Trigger redraw with emptied data
m.redraw();
this.requestInFlight = true;
(this.loadFn ? this.loadFn() : Promise.resolve())
.then(data => {
this.requestInFlight = false;
this.loadedData = data;
this.loaded = true;
this.currentRoute = m.route.get();
m.redraw();
});
},
onupdate: function(vnode) {
var newRoute = m.route.get();
var currentRoute = this.currentRoute;
// If the route has been updated & refetching on update is turned on then re load
if (newRoute != currentRoute && this.refetchOnUpdate && !this.requestInFlight) {
this.fetchAndRedraw();
}
},
view: function(vnode) {
var loader = m(LoadingIndicator, {title: vnode.attrs.title});
return m(".component.with-loader", [
this.loaded ? vnode.attrs.childFn(this.loadedData) : loader
]);
},
};
......@@ -9,6 +9,31 @@
</head>
<body>
<script src="static/vendor/mithril/1.1.6/mithril.min.js"></script>
<script src="components/badge.js"></script>
<script src="components/button-group.js"></script>
<script src="components/draft-mail.js"></script>
<script src="components/drop-down-button.js"></script>
<script src="components/email-list-item.js"></script>
<script src="components/email-list.js"></script>
<script src="components/header-button.js"></script>
<script src="components/important-mail.js"></script>
<script src="components/inbox-mail.js"></script>
<script src="components/lhs-nav-header.js"></script>
<script src="components/lhs-nav-label-list.js"></script>
<script src="components/lhs-nav-page-list.js"></script>
<script src="components/lhs-nav.js"></script>
<script src="components/loading-indicator.js"></script>
<script src="components/mail-page-subnav.js"></script>
<script src="components/main-layout.js"></script>
<script src="components/multi-select-checkbox.js"></script>
<script src="components/nav-item-listing.js"></script>
<script src="components/nav-item.js"></script>
<script src="components/pagination-controls.js"></script>
<script src="components/rhs-header.js"></script>
<script src="components/starred-mail.js"></script>
<script src="components/with-route-triggered-loader.js"></script>
<script src="app.js"></script>
</body>
</html>
......@@ -10,7 +10,7 @@
"scripts": {
"build": "npm run build-static && npm run build-html && npm run build-js",
"build-html": "cp index.html dist/",
"build-js": "cp app.js dist/",
"build-js": "cp app.js dist/ && cp -r components dist/",
"build-static": "mkdir -p dist && cp -r static dist/",
"build-watch": "ls index.html app.js static/css/app.css | entr -rc npm run build",
"serve": "./node_modules/.bin/http-server dist/",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment