From 36a68f8252ed2924bc488f64a40827195cec40ed Mon Sep 17 00:00:00 2001 From: "Shaun A. Noordin" Date: Mon, 6 Mar 2017 15:28:24 +0000 Subject: [PATCH] Add "App Status" banner (#3531) * Basic AppStatus functioning with fake data * More URLs to test * New properly functional static resource * Streamlined with proper comments * Documentation update * Add autofocus * Removed unnecessary autofocus code * Apparently React's autofocus is named autoFocus --- app/partials/app-status.jsx | 87 +++++++++++++++++++++++++++++++++++++ app/partials/app.cjsx | 2 + css/app-status.styl | 17 ++++++++ css/main.styl | 1 + 4 files changed, 107 insertions(+) create mode 100644 app/partials/app-status.jsx create mode 100644 css/app-status.styl diff --git a/app/partials/app-status.jsx b/app/partials/app-status.jsx new file mode 100644 index 0000000000..773c669b00 --- /dev/null +++ b/app/partials/app-status.jsx @@ -0,0 +1,87 @@ +/* +"App Status" Banner +=================== + +The AppStatus banner has one job: it displays a static message to the users, if +it detects a non-empty "status message" file at a specified static URL. +(The static resource is defined by the hardcoded APP_STATUS_URL.) + +Intended use: Zooniverse admins can manually change the status file (e.g. via +AWS CLI) so we can quickly notify zooniverse.org users of certain messages, +notably in emergencies, e.g. "Sorry folks but the animals have escaped, brb" + +Expected Input/Output: +* static file found, is non-empty => show contents of static file in banner +* static file found, is empty => don't show status banner +* static file not found (403, 404, etc) => don't show status banner + +Assumptions: +* the static "status message" resource is stored on a reliable, scalable host. +* fetch() polyfill is available. + +See https://github.com/zooniverse/Panoptes-Front-End/issues/3530 for initial +feature specs. + +(shaun.a.noordin 20170301) +******************************************************************************** + */ + +import React from 'react'; + +const APP_STATUS_URL = 'https://static.zooniverse.org/zooniverse.org-status.txt'; + +export default class AppStatus extends React.Component { + constructor(props) { + super(props); + this.button = null; + + this.state = { + show: false, + message: '', + }; + } + + componentDidMount() { //Display only first time user loads zooniverse.org + fetch(APP_STATUS_URL, { mode: 'cors' }) + .then((response) => { + if (!response.ok) { + console.error('AppStatus: ERROR') + throw Error(response.statusText); + } + + return response.text(); + }) + .then((text) => { + console.log('AppStatus: Received status data from ' + APP_STATUS_URL + '.'); + if (!text || text === '') { + console.log('AppStatus: Nothing to report.'); + } else { + this.setState({ + show: true, + message: text, + }); + } + }) + .catch((err) => { + console.error('AppStatus: No status data from ' + APP_STATUS_URL + '. ', err); + }); + } + + render() { + if (!this.state.show) return null; + if (!this.state.message || this.state.message === '') return null; + + return ( +
+ +
{this.state.message}
+
+ ); + } + + hide() { + this.setState({ + show: false, + }); + } +} diff --git a/app/partials/app.cjsx b/app/partials/app.cjsx index 77ee15fc39..62a521ae87 100644 --- a/app/partials/app.cjsx +++ b/app/partials/app.cjsx @@ -1,5 +1,6 @@ React = require 'react' auth = require 'panoptes-client/lib/auth' +`import AppStatus from './app-status';` IOStatus = require './io-status' AppLayout = require('../layout').default GeordiLogger = require '../lib/geordi-logger' @@ -70,6 +71,7 @@ PanoptesApp = React.createClass render: ->
+ {React.cloneElement @props.children, user: @state.user} diff --git a/css/app-status.styl b/css/app-status.styl new file mode 100644 index 0000000000..ad0a0130ca --- /dev/null +++ b/css/app-status.styl @@ -0,0 +1,17 @@ +.app-status + background: BACKGROUND + border: 1px solid ZOONIVERSE_TEAL + border-radius: 1em + padding: 0.5em 1em + position: fixed + left: 50% + bottom: 1em + transform: translateX(-50%); + width: 80% + max-width: 40em + z-index: 1000 + box-shadow: 0 0 0.5em BACKGROUND + + button.fa-close + float: right + cursor: pointer diff --git a/css/main.styl b/css/main.styl index 7c8a172f3d..c05f54ff2e 100644 --- a/css/main.styl +++ b/css/main.styl @@ -37,6 +37,7 @@ @require './search' @require './subject-viewer' @require './frame-annotator' +@require './app-status' // Home page @require "./home-page"