Skip to content
Open
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
24 changes: 12 additions & 12 deletions app/Classes/RcnApi/Entities/InstructionTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class InstructionTranslation implements \JsonSerializable, Arrayable
'warning',
'anticipated',
'assess_and_plan',
'mitigate_risks',
'mitigate_risk',
'prepare_to_respond',
'recover'
];
Expand Down Expand Up @@ -47,11 +47,11 @@ class InstructionTranslation implements \JsonSerializable, Arrayable
public static function createFromRequest(array $array)
{
$translation = new self();
$translation->lang = $array['lang'];
$translation->webUrl = $array['webUrl'];
$translation->title = $array['title'];
$translation->description = $array['description'];
$translation->stages = new Collection($array['stages']);
$translation->lang = $array['lang'];
$translation->webUrl = $array['webUrl'];
$translation->title = $array['title'];
$translation->description = $array['description'];
$translation->stages = new Collection($array['stages']);
return $translation;
}

Expand All @@ -60,12 +60,12 @@ public static function createFromResponse(array $array)
{
$translation = new self();

$translation->id = $array['id'];
$translation->lang = $array['lang'];
$translation->webUrl = $array['webUrl'];
$translation->title = $array['title'];
$translation->description = $array['description'];
$translation->stages = new Collection($array['stages']);
$translation->id = $array['id'];
$translation->lang = $array['lang'];
$translation->webUrl = $array['webUrl'];
$translation->title = $array['title'];
$translation->description = $array['description'];
$translation->stages = new Collection($array['stages']);
$translation->createdAt = new \DateTimeImmutable($array['createdAt']);
$translation->published = $array['published'];
return $translation;
Expand Down
20 changes: 13 additions & 7 deletions app/Classes/RcnApi/Importer/BulkUploadTemplateExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,31 @@ class BulkUploadTemplateExport implements FromArray, ShouldAutoSize, WithEvents
private $nationalSociety;
private $region;
private $headings = [
'Title', 'Description', 'URL', 'Hazard', 'Urgency Level', 'Safety Message'
'Title',
'Description',
'URL',
'Hazard',
'Urgency Level',
'Safety Message'
];
private $urgencyLevels = '"Immediate,Warning,Anticipated,Assess and Plan,Mitigate Risks,Prepare to Respond,Recover"';
private $urgencyLevels = '"Immediate,Warning,Anticipated,Assess and Plan,Mitigate Risk,Prepare to Respond,Recover"';

private $eventTypesDropdown = [];

private $data;

public function __construct(string $nationalSociety, string $region,array $data, int $maxSupportingMessages)
public function __construct(string $nationalSociety, string $region, array $data, int $maxSupportingMessages)
{
$eventTypes = EventType::whereNotIn('code', ['other'])->get()->toArray();
$this->nationalSociety = $nationalSociety;
$this->eventTypesDropdown = '"' . implode(',', array_map(function ($event) {
return "{$event['name']}";
}, $eventTypes)) . '"';
return "{$event['name']}";
}, $eventTypes)) . '"';
$this->subnational = $region;
$this->data = $data;
if($maxSupportingMessages <= 0) $maxSupportingMessages = 3;
for($i = 0; $i< $maxSupportingMessages; $i++){
if ($maxSupportingMessages <= 0)
$maxSupportingMessages = 3;
for ($i = 0; $i < $maxSupportingMessages; $i++) {
$this->headings[] = 'Supporting Message ' . ($i + 1);
}

Expand Down
9 changes: 6 additions & 3 deletions app/Http/Requests/UserListRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public function rules()
{
return [
'orderBy' => 'in:first_name,last_name,organisation,industry_type,created_at,last_logged_in_at',
'sort' => 'in:asc,desc'
'sort' => 'in:asc,desc',
'filters.search' => 'nullable|string|min:3|max:191'
];
}

Expand All @@ -36,8 +37,10 @@ public function getUserQuery(): UserQuery
$userQuery->setOrderBy($orderBy);
$userQuery->setSort($sort);

foreach ($this->get('filters', []) as $column => $value) {
$userQuery->addFilter($column, $value);
$filters = $this->get('filters', $this->get('filters\\', []));

foreach ($filters as $column => $value) {
$userQuery->addFilter(rtrim($column, '\\'), $value);
}

return $userQuery;
Expand Down
20 changes: 19 additions & 1 deletion app/Repositories/Access/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ public function queryUsers(UserQuery $userQuery): Builder
});
});

$search = trim($userQuery->getFilters()->get('search', ''));
if (mb_strlen($search) >= 3) {
$this->applySearchFilter($builder, $search);
}

$society = $userQuery->getFilters()->only(['society'])->first();
if ($society) {
$builder->whereHas('organisations', function ($query) use ($society) {
Expand Down Expand Up @@ -214,12 +219,25 @@ public function queryUsers(UserQuery $userQuery): Builder
}

if (in_array($userQuery->getOrderBy(), ['first_name', 'last_name', 'organisation', 'industry_type'])) {
$builder->orderByRaw('(SELECT ' . $userQuery->getOrderBy() . ' FROM user_profiles WHERE user_profiles.user_id = users.id) ' . $userQuery->getSort());
$builder->orderByRaw('(SELECT ' . $userQuery->getOrderBy() . ' FROM user_profiles WHERE user_profiles.user_id = users.id AND user_profiles.deleted_at IS NULL ORDER BY user_profiles.id DESC LIMIT 1) ' . $userQuery->getSort());
}

return $builder;
}

private function applySearchFilter(Builder $builder, string $search)
{
$profileMatch = 'MATCH(user_profiles.first_name, user_profiles.last_name) AGAINST (? IN NATURAL LANGUAGE MODE)';
$emailMatch = 'MATCH(users.email) AGAINST (? IN NATURAL LANGUAGE MODE)';
$profileScore = "(SELECT {$profileMatch} FROM user_profiles WHERE user_profiles.user_id = users.id AND user_profiles.deleted_at IS NULL ORDER BY user_profiles.id DESC LIMIT 1)";
$score = "({$emailMatch} + COALESCE({$profileScore}, 0))";

$builder->select('users.*')
->selectRaw("{$score} as search_score", [$search, $search])
->whereRaw("({$emailMatch} > 0 OR EXISTS (SELECT 1 FROM user_profiles WHERE user_profiles.user_id = users.id AND user_profiles.deleted_at IS NULL AND {$profileMatch} > 0))", [$search, $search])
->orderBy('search_score', 'desc');
}

public function deactivate(User $user)
{
$user->activated = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

class AddFulltextIndexesForUserSearch extends Migration
{

public function up()
{
if (env('DB_CONNECTION') !== 'mysql') {
return;
}

if (!$this->indexExists('users', 'users_email_fulltext_search')) {
DB::statement('ALTER TABLE users ADD FULLTEXT users_email_fulltext_search(email)');
}

$this->dropIndexIfExists('user_profiles', 'user_profiles_search_fulltext');
DB::statement('ALTER TABLE user_profiles ADD FULLTEXT user_profiles_search_fulltext(first_name, last_name)');
}


public function down()
{
if (env('DB_CONNECTION') !== 'mysql') {
return;
}

$this->dropIndexIfExists('users', 'users_email_fulltext_search');
$this->dropIndexIfExists('user_profiles', 'user_profiles_search_fulltext');
}

private function dropIndexIfExists(string $table, string $index)
{
if ($this->indexExists($table, $index)) {
DB::statement("ALTER TABLE {$table} DROP INDEX {$index}");
}
}

private function indexExists(string $table, string $index): bool
{
return (bool) DB::select(
DB::raw(
"SHOW KEYS
FROM {$table}
WHERE Key_name='{$index}'"
)
);
}
}
7 changes: 5 additions & 2 deletions resources/assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ Vue.use(VueMoment)

Vue.use(TscGTAG)

Vue.use(GoogleAuth, { client_id: window.config.google.client_id, scopes: 'profile email openid' })
Vue.googleAuth().load()
const googleClientId = window.config?.google?.client_id
if (googleClientId) {
Vue.use(GoogleAuth, { client_id: googleClientId, scopes: 'profile email openid' })
Vue.googleAuth().load()
}

Vue.config.productionTip = false

Expand Down
4 changes: 2 additions & 2 deletions resources/assets/js/pages/content/editWhatnow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ export default {
'warning',
'anticipated',
'assess_and_plan',
'mitigate_risks',
'mitigate_risk',
'prepare_to_respond',
'recover'
],
Expand All @@ -358,7 +358,7 @@ export default {
{
value: 'disaster_risk_reduction',
text: this.$t('content.edit_whatnow.disaster_risk_reduction'),
stages: ['assess_and_plan', 'mitigate_risks', 'prepare_to_respond'],
stages: ['assess_and_plan', 'mitigate_risk', 'prepare_to_respond'],
description: this.$t('content.edit_whatnow.disaster_risk_reduction_description')
},
{
Expand Down
4 changes: 2 additions & 2 deletions resources/assets/js/pages/content/selectSociety.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
v-model="selectedSoc"
class="w-100 v-select-custom"
:options="listOfSocieties"
label="name" :disabled="listOfSocieties.length === 0"
label="name" :disabled="disabled || listOfSocieties.length === 0"
:placeholder="$t('content.whatnow.no_soc')">
<template slot="option" slot-scope="option">
<div class="ml-2 rtl-mr-2 dropdown-option">
Expand All @@ -23,7 +23,7 @@ import { mapGetters } from 'vuex'
import * as permissionsList from '../../store/permissions'

export default {
props: ['selected', 'staynull', 'dontfilter', 'countryCode'],
props: ['selected', 'staynull', 'dontfilter', 'countryCode', 'disabled'],
async mounted () {
this.loading = true
await this.fetchOrganisations()
Expand Down
4 changes: 2 additions & 2 deletions resources/assets/js/pages/content/whatnowContentItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export default {
{
value: 'disaster_risk_reduction',
text: this.$t('content.edit_whatnow.disaster_risk_reduction'),
stages: ['assess_and_plan', 'mitigate_risks', 'prepare_to_respond'],
stages: ['assess_and_plan', 'mitigate_risk', 'prepare_to_respond'],
description: this.$t('content.edit_whatnow.disaster_risk_reduction_description')
},
{
Expand Down Expand Up @@ -271,7 +271,7 @@ export default {
.btn {
font-size: 14px;
}
}
}
}

.hazard-cards-container {
Expand Down
6 changes: 3 additions & 3 deletions resources/assets/js/pages/content/whatnowSummary.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default {
'warning',
'anticipated',
'assess_and_plan',
'mitigate_risks',
'mitigate_risk',
'prepare_to_respond',
'recover'
],
Expand All @@ -50,7 +50,7 @@ export default {
{
value: 'disaster_risk_reduction',
text: this.$t('content.edit_whatnow.disaster_risk_reduction'),
stages: ['assess_and_plan', 'mitigate_risks', 'prepare_to_respond'],
stages: ['assess_and_plan', 'mitigate_risk', 'prepare_to_respond'],
description: this.$t('content.edit_whatnow.disaster_risk_reduction_description')
},
{
Expand Down Expand Up @@ -123,4 +123,4 @@ export default {
color: $grey;
}
}
</style>
</style>
Loading