Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tools #1318

Closed
wants to merge 2 commits into from
Closed

Tools #1318

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ services:
- ./web/themes:/opt/drupal/web/themes
- /opt/drupal/web/modules/contrib
- /opt/drupal/web/themes/contrib
- ./tools:/opt/drupal/tools

# Map in saved configuration. This is used to import configuration and it
# is also where configuration gets exported to. The target/container
Expand Down
188 changes: 188 additions & 0 deletions tools/wxcalc/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
<script language="JavaScript">
function decideConvert(temp) {
var temp = parseFloat(document.Convert.Temp.value);

if (document.Convert.tempunit[0].checked) {
document.Convert.Fahr.value = roundOff(temp);
document.Convert.Cels.value = roundOff(convertFtoC(temp));
document.Convert.Kel.value = roundOff(convertFtoK(temp));
document.Convert.Rank.value = roundOff(convertFtoR(temp));
} else if (document.Convert.tempunit[1].checked) {
document.Convert.Fahr.value = roundOff(convertCtoF(temp));
document.Convert.Cels.value = roundOff(temp);
document.Convert.Kel.value = roundOff(convertCtoK(temp));
document.Convert.Rank.value = roundOff(convertCtoR(temp));
} else if (document.Convert.tempunit[2].checked) {
document.Convert.Fahr.value = roundOff(convertKtoF(temp));
document.Convert.Cels.value = roundOff(convertKtoC(temp));
document.Convert.Kel.value = roundOff(temp);
document.Convert.Rank.value = roundOff(convertKtoR(temp));
} else if (document.Convert.tempunit[3].checked) {
document.Convert.Fahr.value = roundOff(convertRtoF(temp));
document.Convert.Cels.value = roundOff(convertRtoC(temp));
document.Convert.Kel.value = roundOff(convertRtoK(temp));
document.Convert.Rank.value = roundOff(temp);
}
}
function convertFtoC(Fahr) {
Cels = 0.55556 * (Fahr - 32);
return Cels;
}

function convertFtoK(Fahr) {
Kelvin = 0.5556 * (Fahr - 32) + 273.15;
return Kelvin;
}

function convertFtoR(Fahr) {
Rankin = Fahr + 459.67;
return Rankin;
}

function convertCtoF(Cels) {
Fahr = 1.8 * Cels + 32;
return Fahr;
}

function convertCtoK(Cels) {
Kelvin = Cels + 273.15;
return Kelvin;
}

function convertCtoR(Cels) {
Rankin = 1.8 * Cels + 32 + 459.67;
return Rankin;
}

function convertKtoC(Kelvin) {
Cels = Kelvin - 273.15;
return Cels;
}

function convertKtoF(Kelvin) {
Fahr = 1.8 * (Kelvin - 273.15) + 32;
return Fahr;
}

function convertKtoC(Kelvin) {
Cels = Kelvin - 273.15;
return Cels;
}

function convertKtoR(Kelvin) {
Rankin = 1.8 * (Kelvin - 273.15) + 32 + 459.67;
return Rankin;
}

function convertRtoF(Rankin) {
Fahr = Rankin - 459.67;
return Fahr;
}

function convertRtoC(Rankin) {
Cels = 0.55556 * (Rankin - 459.67 - 32);
return Cels;
}

function convertRtoK(Rankin) {
Kelvin = 0.55556 * (Rankin - 459.67 - 32) + 273.15;
return Kelvin;
}

function roundOff(value) {
value = Math.round(100 * value) / 100;
return value;
}

function setToNull() {
document.Convert.Fahr.value = "";
document.Convert.Cels.value = "";
document.Convert.Kel.value = "";
document.Convert.Rank.value = "";
document.Convert.Temp.value = "";
}
</script>

<table cellpadding="4" cellspacing="0" width="525">
<tbody>
<tr>
<td>
<h2>Temperature Unit Converter</h2>

<h5>
by <a href="mailto:[email protected]">Tim Brice</a> and
<a href="mailto:[email protected]">Todd Hall</a>
</h5>

<p class="text-bold">Enter a temperature that you would like:</p>

<form name="Convert">
<table width="100%">
<thead>
<tr>
<td><input name="Temp" size="6" type="text" /></td>
<th>Answers:</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<input
checked="checked"
name="tempunit"
type="radio"
value="on"
/>
Fahrenheit
</td>
<td><input name="Fahr" size="6" type="text" /> ℉</td>
</tr>
<tr>
<td>
<input name="tempunit" type="radio" value="on" /> Celsius
</td>
<td><input name="Cels" size="6" type="text" /> ℃</td>
</tr>
<tr>
<td>
<input name="tempunit" type="radio" value="on" /> Kelvin
</td>
<td><input name="Kel" size="6" type="text" /> K</td>
</tr>
<tr>
<td>
<input name="tempunit" type="radio" value="on" /> Rankine
</td>
<td><input name="Rank" size="6" type="text" /> Rankine</td>
</tr>
<tr>
<td>
<input
onclick="decideConvert(document.Convert.Temp.value)"
type="button"
value="Convert"
/>
</td>
<td>
<input
onclick="setToNull()"
type="button"
value="Clear Values"
/>
</td>
</tr>
</tbody>
</table>
</form>

<p>&nbsp;</p>

<h5>
<a href="/media/epz/wxcalc/tempConvert.pdf"
>What are the formulas for the temperature conversion script?
</a>
</h5>
</td>
</tr>
</tbody>
</table>
70 changes: 70 additions & 0 deletions web/modules/weather_routes/src/Controller/ToolsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace Drupal\weather_routes\Controller;

use Drupal\node\Entity\Node;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

/**
* Controller routines for securitytxt routes.
*/
class ToolsController extends ControllerBase
{
/**
* Format the file content.
*
* @return \Symfony\Component\HttpFoundation\Response
* The security.txt file as a response object with a content type of
* 'text/plain'.
*/
public function toolIndex($name)
{
$path = realpath(getcwd() . "/../tools/" . $name);
if ($path === false) {
throw new NotFoundHttpException();
}

$html = file_get_contents($path . "/index.html");
$tags = \Drupal\Component\Utility\Xss::getAdminTagList();
$balls = \Drupal\Component\Utility\Xss::filterAdmin($html);

return [
"content" => [
"#type" => "markup",
"#markup" => \Drupal\Core\Render\Markup::create($html),
],
];
}

public function toolFile($name, $file)
{
$content =
"Contact: [email protected]\nExpires: 2028-03-27T17:00:00.000Z\n";
$content .=
"Policy: https://www.commerce.gov/vulnerability-disclosure-policy\n";
$content .=
"Form: https://doc.responsibledisclosure.com/hc/en-us/requests/new";
$response = new Response($content, 200, [
"Content-Type" => "text/plain",
]);

return $response;
}

public function toolSubFile($name, $dir, $file)
{
$content =
"Contact: [email protected]\nExpires: 2028-03-27T17:00:00.000Z\n";
$content .=
"Policy: https://www.commerce.gov/vulnerability-disclosure-policy\n";
$content .=
"Form: https://doc.responsibledisclosure.com/hc/en-us/requests/new";
$response = new Response($content, 200, [
"Content-Type" => "text/plain",
]);

return $response;
}
}
27 changes: 26 additions & 1 deletion web/modules/weather_routes/weather_routes.routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,32 @@ weather_routes.security:
requirements:
# Public endpoint
_access: 'TRUE'


weather_routes.tools:
path: '/tools/{name}'
defaults:
_controller: \Drupal\weather_routes\Controller\ToolsController::toolIndex
requirements:
_access: 'TRUE'
name: .*
weather_routes.tools.file:
path: '/tools/{name}/{file}'
defaults:
_controller: \Drupal\weather_routes\Controller\ToolsController::toolFile
requirements:
_access: 'TRUE'
name: .*
file: .*
weather_routes.tools.subfile:
path: '/tools/{name}/{dir}/{file}'
defaults:
_controller: \Drupal\weather_routes\Controller\ToolsController::toolSubFile
requirements:
_access: 'TRUE'
name: .*
dir: .*
file: .*

weather_routes.point:
path: '/point/{lat}/{lon}'
defaults:
Expand Down
Loading