framadate-responsive/documentation/injectables/PollUtilities.html
2020-02-19 17:12:54 +01:00

426 lines
14 KiB
HTML

<!doctype html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>framadate-funky-frontend documentation</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="../images/favicon.ico">
<link rel="stylesheet" href="../styles/style.css">
</head>
<body>
<div class="navbar navbar-default navbar-fixed-top visible-xs">
<a href="../" class="navbar-brand">framadate-funky-frontend documentation</a>
<button type="button" class="btn btn-default btn-menu ion-ios-menu" id="btn-menu"></button>
</div>
<div class="xs-menu menu" id="mobile-menu">
<div id="book-search-input" role="search"><input type="text" placeholder="Type to search"></div> <compodoc-menu></compodoc-menu>
</div>
<div class="container-fluid main">
<div class="row main">
<div class="hidden-xs menu">
<compodoc-menu mode="normal"></compodoc-menu>
</div>
<!-- START CONTENT -->
<div class="content injectable">
<div class="content-data">
<ol class="breadcrumb">
<li>Injectables</li>
<li>PollUtilities</li>
</ol>
<ul class="nav nav-tabs" role="tablist">
<li class="active">
<a href="#info" role="tab" id="info-tab" data-toggle="tab" data-link="info">Info</a>
</li>
<li >
<a href="#source" role="tab" id="source-tab" data-toggle="tab" data-link="source">Source</a>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane fade active in" id="c-info">
<p class="comment">
<h3>File</h3>
</p>
<p class="comment">
<code>src/app/config/PollUtilities.ts</code>
</p>
<section>
<h3 id="index">Index</h3>
<table class="table table-sm table-bordered index-table">
<tbody>
<tr>
<td class="col-md-4">
<h6><b>Methods</b></h6>
</td>
</tr>
<tr>
<td class="col-md-4">
<ul class="index-list">
<li>
<a href="#makeHeaders">makeHeaders</a>
</li>
<li>
<a href="#makeSlug">makeSlug</a>
</li>
<li>
<a href="#makeUuid">makeUuid</a>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
</section>
<section>
<h3 id="methods">
Methods
</h3>
<table class="table table-sm table-bordered">
<tbody>
<tr>
<td class="col-md-4">
<a name="makeHeaders"></a>
<span class="name">
<b>
makeHeaders
</b>
<a href="#makeHeaders"><span class="icon ion-ios-link"></span></a>
</span>
</td>
</tr>
<tr>
<td class="col-md-4">
<code>makeHeaders(bodyContent?: <a href="https://www.typescriptlang.org/docs/handbook/basic-types.html" target="_blank">any</a>)</code>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="48"
class="link-to-prism">src/app/config/PollUtilities.ts:48</a></div>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>prepare headers like the charset and json type for any call to the backend</p>
</div>
<div class="io-description">
<b>Parameters :</b>
<table class="params">
<thead>
<tr>
<td>Name</td>
<td>Type</td>
<td>Optional</td>
</tr>
</thead>
<tbody>
<tr>
<td>bodyContent</td>
<td>
<code><a href="https://www.typescriptlang.org/docs/handbook/basic-types.html" target="_blank" >any</a></code>
</td>
<td>
Yes
</td>
</tr>
</tbody>
</table>
</div>
<div>
</div>
<div class="io-description">
<b>Returns : </b> <code>{ headers: any; body: any; }</code>
</div>
<div class="io-description">
</div>
</td>
</tr>
</tbody>
</table>
<table class="table table-sm table-bordered">
<tbody>
<tr>
<td class="col-md-4">
<a name="makeSlug"></a>
<span class="name">
<b>
makeSlug
</b>
<a href="#makeSlug"><span class="icon ion-ios-link"></span></a>
</span>
</td>
</tr>
<tr>
<td class="col-md-4">
<code>makeSlug(config: <a href="../classes/PollConfig.html">PollConfig</a>)</code>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="24"
class="link-to-prism">src/app/config/PollUtilities.ts:24</a></div>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>make a uniq slug for the current poll creation</p>
</div>
<div class="io-description">
<b>Parameters :</b>
<table class="params">
<thead>
<tr>
<td>Name</td>
<td>Type</td>
<td>Optional</td>
</tr>
</thead>
<tbody>
<tr>
<td>config</td>
<td>
<code><a href="../classes/PollConfig.html" target="_self" >PollConfig</a></code>
</td>
<td>
No
</td>
</tr>
</tbody>
</table>
</div>
<div>
</div>
<div class="io-description">
<b>Returns : </b> <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank" >string</a></code>
</div>
<div class="io-description">
</div>
</td>
</tr>
</tbody>
</table>
<table class="table table-sm table-bordered">
<tbody>
<tr>
<td class="col-md-4">
<a name="makeUuid"></a>
<span class="name">
<b>
makeUuid
</b>
<a href="#makeUuid"><span class="icon ion-ios-link"></span></a>
</span>
</td>
</tr>
<tr>
<td class="col-md-4">
<code>makeUuid()</code>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="13"
class="link-to-prism">src/app/config/PollUtilities.ts:13</a></div>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>generate unique id to have a default url for future poll</p>
</div>
<div class="io-description">
<b>Returns : </b> <code><a href="https://www.typescriptlang.org/docs/handbook/basic-types.html" target="_blank" >any</a></code>
</div>
</td>
</tr>
</tbody>
</table>
</section>
</div>
<div class="tab-pane fade tab-source-code" id="c-source">
<pre class="line-numbers compodoc-sourcecode"><code class="language-typescript">import {HttpHeaders} from &quot;@angular/common/http&quot;;
import {PollConfig} from &quot;./PollConfig&quot;;
import {Injectable} from &quot;@angular/core&quot;;
@Injectable({
providedIn: &#x27;root&#x27;
})
export class PollUtilities {
// utils functions
/**
* generate unique id to have a default url for future poll
*/
makeUuid() {
return &#x27;xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx&#x27;.replace(/[xy]/g, function (c) {
var r &#x3D; Math.random() * 16 | 0, v &#x3D; c &#x3D;&#x3D; &#x27;x&#x27; ? r : (r &amp; 0x3 | 0x8);
return v.toString(16);
});
}
/**
* make a uniq slug for the current poll creation
* @param str
*/
makeSlug(config: PollConfig) {
let str &#x3D; &#x27;&#x27;;
str &#x3D; config.creationDate.getFullYear() + &#x27;_&#x27; + (config.creationDate.getMonth() + 1) + &#x27;_&#x27; + config.creationDate.getDate() + &#x27;_&#x27; + config.myName + &#x27;_&#x27; + config.title;
str &#x3D; str.replace(/^\s+|\s+$/g, &#x27;&#x27;); // trim
str &#x3D; str.toLowerCase();
// remove accents, swap ñ for n, etc
var from &#x3D; &quot;àáäâèéëêìíïîòóöôùúüûñç·/_,:;&quot;;
var to &#x3D; &quot;aaaaeeeeiiiioooouuuunc------&quot;;
for (var i &#x3D; 0, l &#x3D; from.length; i &lt; l; i++) {
str &#x3D; str.replace(new RegExp(from.charAt(i), &#x27;g&#x27;), to.charAt(i));
}
str &#x3D; str.replace(/[^a-z0-9 -]/g, &#x27;&#x27;) // remove invalid chars
.replace(/\s+/g, &#x27;-&#x27;) // collapse whitespace and replace by -
.replace(/-+/g, &#x27;-&#x27;); // collapse dashes
return str;
}
/**
* prepare headers like the charset and json type for any call to the backend
* @param bodyContent
*/
makeHeaders(bodyContent?: any) {
const headerDict &#x3D; {
&#x27;Charset&#x27;: &#x27;UTF-8&#x27;,
&#x27;Content-Type&#x27;: &#x27;application/json&#x27;,
&#x27;Accept&#x27;: &#x27;application/json&#x27;,
&#x27;Access-Control-Allow-Methods&#x27;: &#x27;GET, POST, PUT, DELETE, OPTIONS&#x27;,
&#x27;Access-Control-Allow-Origin&#x27;: &#x27;*&#x27;
};
const requestOptions &#x3D; {
headers: new HttpHeaders(headerDict),
body: bodyContent
};
return requestOptions;
}
}
</code></pre>
</div>
</div>
</div><div class="search-results">
<div class="has-results">
<h1 class="search-results-title"><span class='search-results-count'></span> result-matching "<span class='search-query'></span>"</h1>
<ul class="search-results-list"></ul>
</div>
<div class="no-results">
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
</div>
</div>
</div>
<!-- END CONTENT -->
</div>
</div>
<script>
var COMPODOC_CURRENT_PAGE_DEPTH = 1;
var COMPODOC_CURRENT_PAGE_CONTEXT = 'injectable';
var COMPODOC_CURRENT_PAGE_URL = 'PollUtilities.html';
</script>
<script src="../js/libs/custom-elements.min.js"></script>
<script src="../js/libs/lit-html.js"></script>
<!-- Required to polyfill modern browsers as code is ES5 for IE... -->
<script src="../js/libs/custom-elements-es5-adapter.js" charset="utf-8" defer></script>
<script src="../js/menu-wc.js" defer></script>
<script src="../js/libs/bootstrap-native.js"></script>
<script src="../js/libs/es6-shim.min.js"></script>
<script src="../js/libs/EventDispatcher.js"></script>
<script src="../js/libs/promise.min.js"></script>
<script src="../js/libs/zepto.min.js"></script>
<script src="../js/compodoc.js"></script>
<script src="../js/tabs.js"></script>
<script src="../js/menu.js"></script>
<script src="../js/libs/clipboard.min.js"></script>
<script src="../js/libs/prism.js"></script>
<script src="../js/sourceCode.js"></script>
<script src="../js/search/search.js"></script>
<script src="../js/search/lunr.min.js"></script>
<script src="../js/search/search-lunr.js"></script>
<script src="../js/search/search_index.js"></script>
<script src="../js/lazy-load-graphs.js"></script>
</body>
</html>