1
0
mirror of https://github.com/ascribe/onion.git synced 2025-01-03 10:25:08 +01:00

Reorganize utils to prepare for move to ascribe/react-components

This commit is contained in:
Brett Sun 2016-02-15 15:47:25 +01:00
parent d5c3024375
commit 4a860364d3
16 changed files with 75 additions and 81 deletions

View File

@ -18,7 +18,7 @@ import requests from './utils/requests';
import { updateApiUrls } from './constants/api_urls';
import { getDefaultSubdomainSettings, getSubdomainSettings } from './utils/constants_utils';
import { initLogging } from './utils/error_utils';
import { getSubdomain } from './utils/general_utils';
import { getSubdomain } from './utils/url_utils';
import EventActions from './actions/event_actions';

View File

@ -4,7 +4,7 @@ import React from 'react';
import classnames from 'classnames';
import { AclInformationText } from '../../constants/acl_information_text';
import { replaceSubstringAtIndex, sanitize, intersectLists } from '../../utils/general_utils';
import { sanitize, intersectLists } from '../../utils/general_utils';
import { getLangText } from '../../utils/lang_utils';
@ -37,33 +37,34 @@ let AclInformation = React.createClass({
}
},
getInfoText(title, info, example){
const aim = this.props.aim;
getInfoText(title, info, example) {
const { aim } = this.props;
if(aim) {
if(aim === 'form') {
if (aim) {
const exampleText = ` (e.g. ${example})`;
if (aim === 'form') {
return (
<p>
<span className="info">
{replaceSubstringAtIndex(info.slice(2), 's ', ' ')}
{`${info.replace('s ', ' ')}`}
</span>
<span className="example">
{' ' + example}
{exampleText}
</span>
</p>
);
}
else if(aim === 'button') {
} else if (aim === 'button') {
return (
<p>
<span className="title">
{title}
</span>
<span className="info">
{info + ' '}
{` - ${info}`}
</span>
<span className="example">
{example}
{exampleText}
</span>
</p>
);

View File

@ -5,8 +5,6 @@ import React from 'react';
import Form from '../ascribe_forms/form';
import Property from '../ascribe_forms/property';
import { replaceSubstringAtIndex } from '../../utils/general_utils';
let HistoryIterator = React.createClass({
propTypes: {
@ -14,15 +12,16 @@ let HistoryIterator = React.createClass({
},
composeHistoryDescription(historicalEvent) {
if(historicalEvent.length === 3) {
if (historicalEvent.length === 3) {
// We want to get the capturing group without the quotes,
// which is why we access the match list at index 1 and not 0
const contractName = historicalEvent[1].match(/\"(.*)\"/)[1];
const historicalEventDescription = replaceSubstringAtIndex(historicalEvent[1], `"${contractName}"`, '');
const historicalEventDescription = historicalEvent[1].replace(`"${contractName}"`, '');
return (
<span>
{historicalEventDescription}
<a className="anchor-no-expand-print"
<a
className="anchor-no-expand-print"
target="_blank"
href={historicalEvent[2]}>
{contractName}
@ -39,17 +38,15 @@ let HistoryIterator = React.createClass({
render() {
return (
<Form>
{this.props.history.map((historicalEvent, i) => {
return (
<Property
name={i}
key={i}
label={ historicalEvent[0] }
editable={false}>
<pre className="ascribe-pre">{this.composeHistoryDescription(historicalEvent)}</pre>
</Property>
);
})}
{this.props.history.map((historicalEvent, i) => (
<Property
name={i}
key={i}
label={historicalEvent[0]}
editable={false}>
<pre className="ascribe-pre">{this.composeHistoryDescription(historicalEvent)}</pre>
</Property>
))}
<hr />
</Form>
);

View File

@ -8,7 +8,7 @@ import ProgressBar from 'react-bootstrap/lib/ProgressBar';
import AppConstants from '../../constants/application_constants';
import { escapeHTML } from '../../utils/general_utils';
import { escapeHTML } from '../../utils/dom_utils';
import { InjectInHeadUtils } from '../../utils/inject_utils';
/**

View File

@ -15,8 +15,8 @@ import AppRouteWrapper from '../../../app_route_wrapper';
import Footer from '../../../footer';
import Header from '../../../header';
import { getSubdomain } from '../../../../utils/general_utils';
import { getCookie } from '../../../../utils/fetch_api_utils';
import { getSubdomain } from '../../../../utils/url_utils';
let PRApp = React.createClass({

View File

@ -10,7 +10,7 @@ import AppRouteWrapper from '../../../app_route_wrapper';
import Footer from '../../../footer';
import Header from '../../../header';
import { getSubdomain } from '../../../../utils/general_utils';
import { getSubdomain } from '../../../../utils/url_utils';
let PrizeApp = React.createClass({

View File

@ -8,7 +8,7 @@ import AppRouteWrapper from '../../app_route_wrapper';
import Footer from '../../footer';
import Header from '../../header';
import { getSubdomain } from '../../../utils/general_utils';
import { getSubdomain } from '../../../utils/url_utils';
let WalletApp = React.createClass({

View File

@ -13,25 +13,25 @@ export const AclInformationText = {
'acl_request_unconsign': 'REQUEST UNCONSIGN'
},
'informationSentences': {
'acl_consign': ' - Lets someone represent you in dealing with the work, under the terms you agree to.',
'acl_loan': ' - Lets someone use or put the Work on display for a limited amount of time.',
'acl_share': ' - Lets someone view the Work or Edition via email, but does not give rights to publish or display it.',
'acl_transfer': ' - Changes ownership of an Edition. As with a physical piece Work, Transferring ownership of an Edition does not transfer copyright in the Work.',
'acl_delete': ' - Removes the Work from your Wallet. Note that the previous registration and transfer ' +
'acl_consign': 'Lets someone represent you in dealing with the work, under the terms you agree to.',
'acl_loan': 'Lets someone use or put the Work on display for a limited amount of time.',
'acl_share': 'Lets someone view the Work or Edition via email, but does not give rights to publish or display it.',
'acl_transfer': 'Changes ownership of an Edition. As with a physical piece Work, Transferring ownership of an Edition does not transfer copyright in the Work.',
'acl_delete': 'Removes the Work from your Wallet. Note that the previous registration and transfer ' +
'history will still exist on the blockchain and cannot be deleted.',
'acl_create_editions': ' Lets the artist set a fixed number of editions of a work which can then be transferred, guaranteeing each edition is authentic and from the artist.',
'acl_create_editions': 'Lets the artist set a fixed number of editions of a work which can then be transferred, guaranteeing each edition is authentic and from the artist.',
'acl_unconsign': 'Ends the consignment agreement between the owner and a consignee.',
'acl_request_unconsign': 'Lets the owner ask the consignee to confirm that they will no longer manage the work.'
},
'exampleSentences': {
'acl_consign': '(e.g. an artist Consigns 10 Editions of her new Work to a gallery ' +
'so the gallery can sell them on her behalf, under the terms the artist and the gallery have agreed to)',
'acl_loan': '(e.g. a collector Loans a Work to a gallery for one month for display in the gallery\'s show)',
'acl_share': '(e.g. a photographer Shares proofs of a graduation photo with the graduate\'s grandparents by email)',
'acl_transfer': '(e.g. a musician Transfers limited edition 1 of 10 of her new album to a very happy fan)',
'acl_delete': '(e.g. an artist uploaded the wrong file and doesn\'t want it cluttering his Wallet, so he Deletes it)',
'acl_create_editions': '(e.g. A company commissions a visual artists to create three limited edition prints for a giveaway)',
'acl_unconsign': '(e.g. An artist regains full control over their work and releases the consignee of any rights or responsibilities)',
'acl_request_unconsign': '(e.g. An artist submits an unconsign request to a gallery after his exhibition ends, as per their agreement)'
'acl_consign': 'An artist Consigns 10 Editions of her new Work to a gallery ' +
'so the gallery can sell them on her behalf, under the terms the artist and the gallery have agreed to',
'acl_loan': 'A collector Loans a Work to a gallery for one month for display in the gallery\'s show',
'acl_share': 'A photographer Shares proofs of a graduation photo with the graduate\'s grandparents by email',
'acl_transfer': 'A musician Transfers limited edition 1 of 10 of her new album to a very happy fan',
'acl_delete': 'An artist uploaded the wrong file and doesn\'t want it cluttering his Wallet, so he Deletes it',
'acl_create_editions': 'A company commissions a visual artists to create three limited edition prints for a giveaway',
'acl_unconsign': 'An artist regains full control over their work and releases the consignee of any rights or responsibilities',
'acl_request_unconsign': 'An artist submits an unconsign request to a gallery after his exhibition ends, as per their agreement'
}
};

View File

@ -5,8 +5,6 @@ import AppConstants from './application_constants';
import getPrizeApiUrls from '../components/whitelabel/prize/constants/prize_api_urls';
import getWalletApiUrls from '../components/whitelabel/wallet/constants/wallet_api_urls';
import { update } from '../utils/general_utils';
let ApiUrls = {
'applications': AppConstants.apiEndpoint + 'applications/',
@ -85,10 +83,11 @@ export function updateApiUrls(type, subdomain) {
if (type === 'prize') {
newUrls = getPrizeApiUrls(subdomain);
} else if(type === 'wallet') {
} else if (type === 'wallet') {
newUrls = getWalletApiUrls(subdomain);
}
update(ApiUrls, newUrls);
Object.assign(ApiUrls, newUrls);
}
export default ApiUrls;

View File

@ -2,7 +2,7 @@
import requests from '../utils/requests';
import { getSubdomain } from '../utils/general_utils';
import { getSubdomain } from '../utils/url_utils';
let LicenseFetcher = {

View File

@ -3,7 +3,7 @@
import requests from '../utils/requests';
import WhitelabelActions from '../actions/whitelabel_actions';
import { getSubdomain } from '../utils/general_utils';
import { getSubdomain } from '../utils/url_utils';
const WhitelabelSource = {

View File

@ -3,7 +3,7 @@
import { altThirdParty } from '../alt';
import EventActions from '../actions/event_actions';
import { getSubdomain } from '../utils/general_utils';
import { getSubdomain } from '../utils/url_utils';
class IntercomHandler {

View File

@ -3,12 +3,11 @@
import history from '../history';
import { altThirdParty } from '../alt';
import EventActions from '../actions/event_actions';
import NotificationActions from '../actions/notification_actions';
import { getSubdomain } from '../utils/general_utils';
import { getSubdomain } from '../utils/url_utils';
class NotificationsHandler {

View File

@ -51,6 +51,18 @@ export function constructHead(headObject){
}
}
/**
* Escape HTML in a string so it can be injected safely using
* React's `dangerouslySetInnerHTML`
*
* @param s the string to be sanitized
*
* Taken from: http://stackoverflow.com/a/17546215/597097
*/
export function escapeHTML(s) {
return document.createElement('div').appendChild(document.createTextNode(s)).parentNode.innerHTML;
}
/**
* Replaces the links and emails in a given string with anchor elements.
*

View File

@ -122,31 +122,6 @@ export function mergeOptions(...l) {
return Object.assign({}, ...l);
}
/**
* In place update of a dictionary
*/
export function update(a, ...l) {
for(let i = 0; i < l.length; i++) {
for (let attrname in l[i]) {
a[attrname] = l[i][attrname];
}
}
return a;
}
/**
* Escape HTML in a string so it can be injected safely using
* React's `dangerouslySetInnerHTML`
*
* @param s the string to be sanitized
*
* Taken from: http://stackoverflow.com/a/17546215/597097
*/
export function escapeHTML(s) {
return document.createElement('div').appendChild(document.createTextNode(s)).parentNode.innerHTML;
}
/**
* Returns a copy of the given object's own and inherited enumerable
* properties, omitting any keys that pass the given filter function.

View File

@ -80,3 +80,14 @@ export function generateOrderingQueryParams(orderBy, orderAsc) {
return interpolation + orderBy;
}
/**
* Extracts the user's subdomain from the browser's window.
* If no subdomain is found (for example on a naked domain), the default "www" is just assumed.
* @return {string} subdomain as a string
*/
export function getSubdomain() {
const { host } = window.location;
const tokens = host.split('.');
return tokens.length > 2 ? tokens[0] : 'www';
}