Skip to content

Commit

Permalink
Merge branch 'develop' - vax-200, sg-1235
Browse files Browse the repository at this point in the history
  • Loading branch information
aekong committed Apr 22, 2021
2 parents 881d5c6 + d039605 commit c4d8331
Show file tree
Hide file tree
Showing 11 changed files with 192 additions and 37 deletions.
22 changes: 13 additions & 9 deletions config/sfgov_vaccine.settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ languages:
rt:
site_label: null
filter_label: 'Other Languages'
minors:
true_text: '16 and older'
false_text: '18 and older'
access_mode:
walk:
short_key: wa
Expand All @@ -44,32 +47,33 @@ access_mode:
radius:
all:
value: Infinity
text: Any distance
text: 'Any distance'
1:
value: ".5"
text: 0.5 mile
value: '.5'
text: '0.5 mile'
2:
value: 1
text: 1 mile
text: '1 mile'
3:
value: 3
text: 3 miles

text: '3 miles'
form_strings:
title: Filters
restrictions: 'Only show sites open to the general public'
available: 'Only show sites with confirmed availability'
language_label: 'Languages spoken'
access_mode_label: Access
eligibility_label: 'Eligibility requirements'
distance_label: Sort by distance
location_label: Enter address or zip
distance_label: 'Sort by distance'
location_label: 'Enter address or zip'
submit_label: Apply
template_strings:
page:
title: 'COVID-19 vaccine sites'
description: 'Find out where to get a vaccine if you''re eligible. Keep checking for appointments. New locations will be added as they''re available. If you need a second dose, contact the location where you got your first dose. <a href=/covid-19-vaccine-san-francisco>Learn more.</a>'
alert: 'You must be eligible in order to get vaccinated. <a href=/getvaccinated>See eligibility criteria</a>'
alert:
value: "<p>You must be eligible in order to get vaccinated. <a href=\"/getvaccinated\">See eligibility criteria</a></p>\r\n"
format: sf_restricted_html
empty:
text_1: 'No sites match your search'
text_2: 'Remove some of the filters to find more sites.'
Expand Down
8 changes: 4 additions & 4 deletions web/modules/custom/sfgov_admin/sfgov_admin.module
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,11 @@ function sfgov_admin_form_content_moderation_entity_moderation_form_alter(&$form
/**
* Implements hook_views_pre_view().
*/
function sfgov_admin_views_pre_view(&$view) {
function sfgov_admin_views_pre_view(ViewExecutable $view) {
if ($view->id() == 'content') {
// Set english as default langcode for admin content list
$filters = $view->getDisplay()->getOption('filters');
$filters["langcode"]["value"] = "en";
// Set english as default langcode for admin content list.
$filters = $view->getDisplay()->getOption('filters');
$filters["langcode"]["value"] = ["en"];
$view->display_handler->overrideOption('filters', $filters);
}
}
4 changes: 2 additions & 2 deletions web/modules/custom/sfgov_vaccine/js/filter_sites.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@
return rtnData;
})
.sort(function (a, b) {
const orderA = a.getAttribute("data-order");
const orderB = b.getAttribute("data-order");
const orderA = parseInt(a.getAttribute("data-order"));
const orderB = parseInt(b.getAttribute("data-order"));

let dataA = orderA;
let dataB = orderB;
Expand Down
1 change: 1 addition & 0 deletions web/modules/custom/sfgov_vaccine/sfgov_vaccine.module
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function sfgov_vaccine_theme() {
return [
'vaccine_widget' => [
'variables' => [
'alert' => NULL,
'template_strings' => NULL,
'filters' => NULL,
'results' => NULL,
Expand Down
4 changes: 4 additions & 0 deletions web/modules/custom/sfgov_vaccine/sfgov_vaccine.services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
services:
sfgov_vaccine.values:
class: Drupal\sfgov_vaccine\Services\VaxValues
arguments: ['@state', '@config.factory']
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Drupal\Core\Template\Attribute;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\ConnectException;
use Drupal\sfgov_vaccine\Services\VaxValues;

/**
* Creates the vaccine sites page.
Expand Down Expand Up @@ -62,15 +63,24 @@ class VaccineController extends ControllerBase {
*/
protected $allData = NULL;

/**
* Get Vaccine-related data.
*
* @var \Drupal\sfgov_vaccine\Services\VaxValues
*/
protected $vaxValues;


/**
* {@inheritdoc}
*/
public function __construct(LanguageManager $languageManager, FormBuilderInterface $formBuilder, ConfigFactory $configFactory, ClientInterface $http_client, LoggerChannelFactoryInterface $loggerFactory) {
public function __construct(LanguageManager $languageManager, FormBuilderInterface $formBuilder, ConfigFactory $configFactory, ClientInterface $http_client, LoggerChannelFactoryInterface $loggerFactory, VaxValues $vaxValues) {
$this->languageManager = $languageManager;
$this->formBuilder = $formBuilder;
$this->configFactory = $configFactory;
$this->httpClient = $http_client;
$this->loggerFactory = $loggerFactory;
$this->vaxValues = $vaxValues;
$this->allData = $this->dataFetch();
}

Expand All @@ -83,22 +93,16 @@ public static function create(ContainerInterface $container) {
$container->get('form_builder'),
$container->get('config.factory'),
$container->get('http_client'),
$container->get('logger.factory')
$container->get('logger.factory'),
$container->get('sfgov_vaccine.values')
);
}

/**
* Get config.
*/
private function settings($value) {
return $this->configFactory->get('sfgov_vaccine.settings')->get($value);
}

/**
* Get the microservice url from config.
*/
private function getAPIUrl() {
return $this->settings('api_url');
return $this->vaxValues->settings('api_url');
}

/**
Expand Down Expand Up @@ -129,7 +133,7 @@ public function dataFetch() {
*/
private function makeAPIData($allData) {

$error_message = $this->settings('error_message');
$error_message = $this->vaxValues->settings('error_message');

return [
'timestamp' => $allData['data']['generated'],
Expand Down Expand Up @@ -158,7 +162,7 @@ private function getSiteAccessModeKeys($site_data) {
$keys = [];
foreach ($access_mode_options as $key => $value) {
if ($value === TRUE) {
$key = $this->settings('access_mode.' . $key . '.short_key');
$key = $this->vaxValues->settings('access_mode.' . $key . '.short_key');
array_push($keys, $key);
}
}
Expand Down Expand Up @@ -199,7 +203,7 @@ private function getSiteAccessModeText($site_data) {
$printed = [];
foreach ($access_mode_options as $key => $value) {
if ($value === TRUE) {
$text = $this->settings('access_mode.' . $key . '.text');
$text = $this->vaxValues->settings('access_mode.' . $key . '.text');
array_push($printed, $this->t($text));
}
}
Expand All @@ -218,7 +222,7 @@ private function getSiteLanguageText($access_data) {

$printed_languages = [];
foreach ($site_data_languages as $short_key => $boolean) {
$language_label = $this->settings(sprintf('languages.%s.site_label', $short_key));
$language_label = $this->vaxValues->settings(sprintf('languages.%s.site_label', $short_key));
if ($boolean === TRUE && !empty($language_label)) {
array_push(
$printed_languages, $this->t($language_label));
Expand All @@ -237,6 +241,21 @@ private function getSiteLanguageText($access_data) {
];
}

/**
* Prepare each site's eligibility text.
*/
private function getSiteEligibilityText($site_data, $group) {

$printed = [];
if (isset($site_data[$group]['allowed'])) {
$site_minor_status = $site_data[$group]['allowed'] ? 'true': 'false';
$text = $this->vaxValues->settings($group . '.' . $site_minor_status . '_text');
$printed_value = $this->t($text);
array_push($printed, $printed_value);
}
return $printed;
}

/**
* Prepare sites for rendering.
*/
Expand All @@ -262,6 +281,7 @@ private function makeResults($allData) {
$results = [];
foreach ($sites as $site_id => $site_data) {

$eligibility_text = $this->getSiteEligibilityText($site_data, 'minors');
$language_keys = $this->getSiteLanguageKeys($site_data['access']);
$language_text = $this->getSiteLanguageText($site_data['access']);
$access_mode_keys = $this->getSiteAccessModeKeys($site_data);
Expand Down Expand Up @@ -307,7 +327,7 @@ private function makeResults($allData) {
'data-available' => $available,
'data-wheelchair' => $wheelchair ? 1 : 0,
// Multi-selects.
'data-language' => $language_keys ? implode('-', $language_keys) : implode('-', $this->settings('languages')),
'data-language' => $language_keys ? implode('-', $language_keys) : implode('-', $this->vaxValues->settings('languages')),
'data-remote-asl' => $language_text['remote_asl'],
'data-access-mode' => implode('-', $access_mode_keys),
'data-lat' => $location['lat'],
Expand All @@ -317,6 +337,7 @@ private function makeResults($allData) {
'restrictions_text' => $restrictions_text,
'location' => $location,
'languages' => $language_text['printed_languages'],
'eligibilities' => $eligibility_text,
'access_modes' => $access_mode_text,
'info_url' => $info_url,
'available' => $available,
Expand All @@ -335,7 +356,8 @@ public function displayPage() {
return [
'#cache' => ['max-age' => 0],
'#theme' => 'vaccine_widget',
'#template_strings' => $this->settings('template_strings'),
'#alert' => $this->vaxValues->getAlert(),
'#template_strings' => $this->vaxValues->settings('template_strings'),
'#api_data' => $this->makeAPIData($this->allData),
'#filters' => $this->makeFilters($this->allData),
'#results' => $this->makeResults($this->allData),
Expand Down
48 changes: 44 additions & 4 deletions web/modules/custom/sfgov_vaccine/src/Form/SettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\sfgov_vaccine\Services\VaxValues;
use Drupal\sfgov_vaccine\VaxValues\Alert;
use Symfony\Component\DependencyInjection\ContainerInterface;
use GuzzleHttp\ClientInterface;
use Drupal\Core\Config\ConfigFactory;

/**
* Settings for the vaccine sites page.
Expand All @@ -20,19 +23,38 @@ class SettingsForm extends ConfigFormBase {
*/
protected $httpClient;


/**
* The configuration factory.
*
* @var Drupal\Core\Config\ConfigFactory
*/
protected $configFactory;

/**
* The configuration factory.
*
* @var Drupal\sfgov_vaccine\VaxValues
*/
protected $vaxValues;

/**
* Class constructor.
*/
public function __construct(ClientInterface $httpClient) {
public function __construct(ClientInterface $httpClient, ConfigFactory $configFactory, VaxValues $vaxValues) {
$this->httpClient = $httpClient;
$this->configFactory = $configFactory;
$this->vaxValues = $vaxValues;
}

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('http_client')
$container->get('http_client'),
$container->get('config.factory'),
$container->get('sfgov_vaccine.values')
);
}

Expand All @@ -52,18 +74,34 @@ public function getFormId() {
return 'vaccine_settings_form';
}

/**
* Get config.
*/
private function settings($value) {
return $this->configFactory->get('sfgov_vaccine.settings')->get($value);
}

/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('sfgov_vaccine.settings');

$form['api_url'] = [
'#type' => 'url',
'#title' => $this->t('Microservice URL'),
'#description' => $this->t('e.g. https://vaccination-site-microservice.vercel.app/api/v1/appointments, https://vaccination-site-microservice-git-automate-site-data-sfds.vercel.app/api/v1/appointments'),
'#default_value' => $config->get('api_url'),
'#default_value' => $this->vaxValues->settings('api_url'),
];

$form['alert'] = [
'#type' => 'text_format',
'#title' => $this->t('Vaccine Page Alert Message'),
'#description' => $this->t('Enter a message for the yellow alert area at /vaccine-sites.'),
'#default_value' => $this->vaxValues->getAlert(),
'#format' => 'sf_restricted_html',
'#allowed_formats' => ['sf_restricted_html'],
];

$form['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Submit'),
Expand Down Expand Up @@ -104,6 +142,8 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$this->config('sfgov_vaccine.settings')
->set('api_url', trim($form_state->getValue('api_url')))
->save();

$this->vaxValues->setAlert($form_state->getValue('alert'));
}

}
Loading

1 comment on commit c4d8331

@josh-chou
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Visit Site

Created multidev environment ci-9637 for sfgov.

Please sign in to comment.