Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 | 121x 100x 100x 100x 319x 99x 99x 100x 100x 1x 1x 100x 51x 180x 180x 180x 180x 78x 102x 102x 141x 141x 141x 30x 111x 9x 102x 337x 337x 337x 337x 337x 119x 337x 57x 57x 337x 305x 305x 215x 90x 32x 32x 31x 19x 12x 12x 32x 122x 7x 4x 4x 2x 1x 1x 2x 4x 15x 15x 15x 11x 4x 26x 5x 26x 15x 15x 15x 15x 15x 5x 15x 7x 15x 3x 1x 21x 14x 7x 4x 9x 9x 21x 16x 7x 1x | /*
* Part of Pleiar.no - a collection of tools for nurses
*
* Copyright (C) Eskild Hustvedt 2018
* Copyright (C) Fagforbundet 2019
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
// @flow
import * as React from 'react';
import { connect } from 'react-redux';
import { PageTitle } from './layout';
import { Row, Col, Input, InputGroup, InputGroupAddon, InputGroupText } from 'reactstrap';
import { setDictSearchString } from '../actions/dictionary';
import data from '../../data/datasett/dictionary.json';
import XCircle from 'react-feather/dist/icons/x-circle';
import ReactMarkdown from 'react-markdown';
import PleiarSearcher from '../searcher';
import RoutingAssistant from '../routing';
import { InfiniteScrollSearchResultRenderer, RequiresPleiarSearcher } from './global-search';
import { Link } from 'react-router-dom';
import { getValueFromLiteralOrEvent } from '../helper.general';
import device from '../helper.device';
import { ExternalLink } from './shared/links';
import { InlineAuthBlock } from './auth';
import auth from '../auth';
import { StructuredData } from './shared/structured-data';
import type { DictionaryEntry as DictionaryEntryType } from '../types/data';
import type { lunrResult } from '../types/libs';
import type { onSyncSignature } from '../routing';
import type { Location } from 'react-router-dom';
import domainToNameMap from '../../data/datasett/website-identification.json';
/**
* A `<Link>` wrapper that returns links relative to `/ordliste/`
*/
class DictionaryLink extends React.PureComponent<{|href: string, children: React.Node|}>
{
// eslint-disable-next-line require-jsdoc
render(): React.Node
{
return <Link to={'/ordliste/'+this.props.href}>{this.props.children}</Link>;
}
}
/**
* Renders a single "read more" entry. It takes a URL and returns a link to
* that URL with the link text being the name of the site. The names are
* hardcoded.
*/
class ReadMoreEntry extends React.PureComponent<{|entry: string|}>
{
// eslint-disable-next-line require-jsdoc
render(): React.Node
{
const link = this.props.entry;
let site: string = '';
for(const entry of domainToNameMap)
{
if(link.indexOf(entry.index) !== -1)
{
site = entry.name;
break;
}
}
let text: string = site;
if(site === "")
{
/* eslint-disable no-console */
console.log('Multi-link entry, but unidentified site: '+link);
text = '???';
}
return <ExternalLink href={link}>{text}</ExternalLink>;
}
}
/**
* Renders a single "see also" dictionary entry through `DictionaryLink`.
*/
class SeeAlsoEntry extends React.PureComponent<{|entry: string |}>
{
// eslint-disable-next-line require-jsdoc
render(): React.Node
{
return <DictionaryLink key={'sea-'+this.props.entry} href={this.props.entry}>{this.props.entry}</DictionaryLink>;
}
}
/**
* Renders an array of elink erntries through a component, generating a nice
* readable list with either , or " og " separating the items, depending on
* where in the line they appear.
*/
class SomeDictEntries extends React.PureComponent<{|entries?: Array<string>, singleEntryRenderer: React.ComponentType<{|entry: string|}>, prefix: string|}>
{
// eslint-disable-next-line require-jsdoc
render(): React.Node
{
const SingleEntryRenderer = this.props.singleEntryRenderer;
const ret = [];
const entries = this.props.entries;
if(entries == undefined)
{
return null;
}
const prefix = this.props.prefix;
for(let entryNo: number = 0; entryNo < entries.length; entryNo++)
{
const entry = entries[entryNo];
ret.push(<SingleEntryRenderer key={entry} entry={entry} />);
if(entryNo+2 == entries.length)
{
ret.push(<span key={entryNo}> og </span>);
}
else if(entryNo+1 < entries.length)
{
ret.push(<span key={entryNo}>, </span>);
}
}
return <span className="readMore"><span>{prefix} </span>{ret}.</span>;
}
}
/**
* Renders a single entry in the dictionary
*
* Props:
* - entry: The entry to render
* - rawEntry: A boolean, if true it will return *just* the entry, with no
* "read more", no title etc. rawEntry implies forceAuth=true and inhibitTitle=true
* - inhibitTitle: A boolean, if true will omit the title of the entry
* - forceAuth: A boolean, if true, will not verify that a user is logged in
* - whitelistedAuthRequiredEntries: The number of whitelisted entries
* displayed before authentication is required. Used to construct the text
* for the {@link InlineAuthBlock}.
*/
class DictionaryEntry extends React.PureComponent<{| entry: DictionaryEntryType, rawEntry?: boolean, inhibitTitle?: boolean, forceAuth?: boolean, whitelistedAuthRequiredEntries?: number |}>
{
// eslint-disable-next-line require-jsdoc
render(): React.Node
{
const dataEntry = this.props.entry;
let title: React.Node = null;
let handbookLink: React.Node = null;
let readMoreOnText: string = "Les mer på";
if (!this.props.inhibitTitle && !this.props.rawEntry)
{
title = <div className="dictionaryTitle" target="_blank">{dataEntry.expression}</div>;
}
if(dataEntry.seeHandbook)
{
handbookLink = <Link to={'/handbok'+dataEntry.seeHandbook}>Les mer i håndboken.</Link>;
readMoreOnText = "Ytterligere informasjon på";
}
let content: React.Node;
if(auth.isAuthenticated() || this.props.forceAuth || this.props.rawEntry)
{
const entry = <ReactMarkdown components={{a: DictionaryLink}}>{dataEntry.description}</ReactMarkdown>;
if(this.props.rawEntry)
{
return entry;
}
content = <span className="auth-content">
{entry}{' '}
<SomeDictEntries entries={dataEntry.seeAlso} singleEntryRenderer={SeeAlsoEntry} prefix="Se også" /> {handbookLink} <SomeDictEntries entries={dataEntry.moreInfoURLs} singleEntryRenderer={ReadMoreEntry} prefix={readMoreOnText} />
</span>;
}
else
{
let text: string = "oppføringer i ordlisten";
if(this.props.whitelistedAuthRequiredEntries !== undefined)
{
if (this.props.whitelistedAuthRequiredEntries > 0)
{
text = "flere oppføringer i ordlisten";
}
else Eif(this.props.whitelistedAuthRequiredEntries === -1)
{
text = 'søk i ordlisten';
}
}
content = <InlineAuthBlock attemptedAccess={text} />;
}
return <Row key={dataEntry.expression} className="dictionaryEntry">
<Col>
{title}
{content}
</Col>
</Row>;
}
}
/**
* Props for `Dictionary`
*/
type DictionaryProps = {|
search: string,
location?: Location,
onSearchUpdate: (string) => void,
|};
/**
* Renders the full dictionary page with a search field and infinite scrolling.
*/
class Dictionary extends React.Component<DictionaryProps>
{
constructor (props: DictionaryProps) // eslint-disable-line require-jsdoc
{
super(props);
}
/**
* Callback, called when either the user types or clicks on a link that
* updates the search value. This gets bound to this instance of
* `Dictionary` in the `constructor`
*/
onChanged (str: string | SyntheticEvent<HTMLInputElement>,forcedPush?: boolean)
{
str = getValueFromLiteralOrEvent(str);
if(str == "")
{
if(forcedPush)
{
RoutingAssistant.push('/ordliste');
}
else
{
RoutingAssistant.replace('/ordliste');
}
}
else
{
RoutingAssistant.generateReplace('/ordliste',str,"auto");
}
this.props.onSearchUpdate(str);
}
/**
* Performs a search and returns the result
*/
getResources (): Array<lunrResult>
{
const search = this.props.search;
let results: Array<lunrResult> = [];
if(search === null || search === "" || !/\w/.test(search))
{
results = data;
}
else
{
results = PleiarSearcher.safePartialSearch(search,(accumulator: Array<lunrResult>,result: lunrResult) =>
{
if(result.ref.indexOf("dictionary") === 0)
{
accumulator.push(result);
}
return accumulator;
});
}
return results;
}
// eslint-disable-next-line require-jsdoc
render(): React.Node
{
const entries = this.getResources();
let autoFocus: boolean = true;
let whitelistedAuthRequiredEntries: number = 5;
if(this.props.search !== null && this.props.search !== undefined && this.props.search != "")
{
whitelistedAuthRequiredEntries = -1;
}
if(device.isTouchScreen())
{
autoFocus = false;
}
return <Row>
<Col lg={{offset:2,size:8}}>
<PageTitle title="Ordliste" />
<h3>Ordliste</h3>
<InputGroup>
<Input autoFocus={autoFocus} placeholder="Søk" value={this.props.search} onChange={(e,force) => this.onChanged(e,force)} name="search" />
<InputGroupAddon addonType="append">
<InputGroupText className="clearSearchField" onClick={ () => { this.onChanged('',true); } }>
<XCircle />
</InputGroupText>
</InputGroupAddon>
</InputGroup>
<hr />
{/* $FlowIssue[prop-missing] Actual flow bug with unions */}
<InfiniteScrollSearchResultRenderer result={entries} search={this.props.search} onPageChange={this.onPageChange} type="dictionary" suggestGlobalSearch={true} whitelistedAuthRequiredEntries={whitelistedAuthRequiredEntries} searchPathPrefix="/ordliste" location={this.props.location} />
</Col>
<StructuredData type="auto" walled={true} />
</Row>;
}
}
const DictionaryContainer = connect(
(state) =>
{
return {
search: state.dictionary.search,
};
},
(dispatch) =>
{
return {
onSearchUpdate(ev: string)
{
dispatch(setDictSearchString(ev));
}
};
}
)(Dictionary);
/**
* Props for DictionaryWrapper
*/
type DictionaryWrapperProps = {| onRouteSync: onSyncSignature |};
/**
* This is a wrapper around Dictionary. It wraps it in a
* RequiresPleiarSearcher component to ensure PleiarSearcher is initialized
* once Dictionary starts rendering.
*/
class DictionaryWrapper extends React.Component<DictionaryWrapperProps>
{
// eslint-disable-next-line require-jsdoc
render(): React.Node
{
const { onRouteSync, ...moreProps } = this.props;
return <RequiresPleiarSearcher component={DictionaryContainer} onRouteSync={onRouteSync} app="dictionary" {...moreProps} />;
}
}
const DictionaryWrapperContainer: React.AbstractComponent<{| |}> = connect<DictionaryWrapperProps,{| |},_,DictionaryWrapperProps,_,_>(
() =>
{
return {};
},
(dispatch): DictionaryWrapperProps =>
{
return {
onRouteSync(search)
{
dispatch(setDictSearchString(search));
},
};
}
)(DictionaryWrapper);
// Public exports
export default DictionaryWrapperContainer;
export { DictionaryEntry };
// Testing exports
export { ReadMoreEntry, Dictionary as DictionaryContainerRaw };
|