-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Michi Hoffmann <[email protected]>
- Loading branch information
Showing
21 changed files
with
564 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
use Migrations\AbstractMigration; | ||
|
||
class AddQuickWins extends AbstractMigration | ||
{ | ||
/** | ||
* Up Method. | ||
* | ||
* More information on this method is available here: | ||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-up-method | ||
* | ||
* @return void | ||
*/ | ||
public function up(): void | ||
{ | ||
$this->table('quick_wins', ['id' => false, 'primary_key' => ['id']]) | ||
->addColumn('id', 'uuid', [ | ||
'default' => null, | ||
'limit' => null, | ||
'null' => false, | ||
]) | ||
->addColumn('sender_user_id', 'uuid', [ | ||
'default' => null, | ||
'limit' => null, | ||
'null' => false, | ||
]) | ||
->addColumn('message', 'string', [ | ||
'default' => null, | ||
'limit' => 4096, | ||
'null' => false, | ||
]) | ||
->addColumn('permalink', 'string', [ | ||
'default' => null, | ||
'limit' => 255, | ||
'null' => false, | ||
]) | ||
->addColumn('created', 'datetime', [ | ||
'default' => null, | ||
'limit' => null, | ||
'null' => true, | ||
]) | ||
->addIndex( | ||
[ | ||
'sender_user_id', | ||
] | ||
) | ||
->create(); | ||
|
||
$this->table('quick_wins') | ||
->addForeignKey( | ||
'sender_user_id', | ||
'users', | ||
'id', | ||
[ | ||
'update' => 'NO_ACTION', | ||
'delete' => 'NO_ACTION', | ||
] | ||
) | ||
->update(); | ||
} | ||
|
||
/** | ||
* Down Method. | ||
* | ||
* More information on this method is available here: | ||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-down-method | ||
* | ||
* @return void | ||
*/ | ||
public function down(): void | ||
{ | ||
$this->table('quick_wins') | ||
->dropForeignKey( | ||
'sender_user_id' | ||
)->save(); | ||
|
||
$this->table('quick_wins')->drop()->save(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<template> | ||
<p class="text-sm pt-2.5" v-html="formattedMessage"></p> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
name: 'FormattedMessage', | ||
props: ['message'], | ||
computed: { | ||
formattedMessage() { | ||
return this.message | ||
.replace(/<(@[^>]+)>/g, (_match, p1) => `<span class="bg-blue-500 text-blue-500 bg-opacity-30 p-0.5 px-1 rounded-sm">${p1}</span>`) | ||
.replace(/ (\w+) <(http[^>]+)>/g, (_match, p1, p2) => ` <a class="underline" href="${p2}">${p1}</a> `) | ||
.replace(/:potato:/g, '🥔'); | ||
}, | ||
}, | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<template> | ||
<div v-if="quickWins.length"> | ||
|
||
<div> | ||
<h2 class="text-lg font-medium leading-6"> | ||
Messages containing #quickwin and 🥔 will be immortalized here | ||
</h2> | ||
</div> | ||
|
||
<div class="mt-8 grid grid-cols-1 gap-y-12 sm:grid-cols-2 sm:gap-x-6 lg:grid-cols-4 xl:gap-x-8 mb-32"> | ||
|
||
<div v-for="(item, index) in quickWins"> | ||
<div | ||
:index="index" | ||
class="flex items-start gap-2.5" | ||
> | ||
<img | ||
class="w-8 h-8 rounded-full" | ||
:src="item.user.slack_picture" | ||
> | ||
<div class="p-4 border border-zinc-300 rounded-e-xl rounded-es-xl"> | ||
<div class=""> | ||
<div class="text-sm font-semibold"> | ||
{{item.user.slack_name}} | ||
</div> | ||
<div class="text-sm font-normal text-zinc-500"> | ||
{{ new Date(item.created).toLocaleDateString('en-us', { year:"numeric", month:"short", day:"numeric"}) }} | ||
</div> | ||
</div> | ||
<FormattedMessage :message="item.message" /> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
</div> | ||
|
||
<div | ||
v-else | ||
class="absolute inset-0 flex items-center justify-center" | ||
> | ||
<h1 class="text-2xl font-extrabold"> | ||
No #quickwins happened so far... | ||
</h1> | ||
</div> | ||
|
||
</template> | ||
|
||
<script> | ||
import { computed } from 'vue' | ||
import { useStore } from 'vuex' | ||
import FormattedMessage from '../components/FormattedMessage.vue' | ||
export default { | ||
name: 'QuickWins', | ||
components: { | ||
FormattedMessage, | ||
}, | ||
setup() { | ||
const store = useStore() | ||
return { | ||
quickWins: computed(() => store.getters.quickWins), | ||
} | ||
}, | ||
} | ||
</script> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace App\Controller\Api; | ||
|
||
use Cake\Http\Response; | ||
|
||
/** | ||
* @property \Authentication\Controller\Component\AuthenticationComponent $Authentication | ||
*/ | ||
class QuickWinsController extends ApiController | ||
{ | ||
/** | ||
* @return \Cake\Http\Response | ||
*/ | ||
public function get(): Response | ||
{ | ||
$quickWinsTable = $this->fetchTable('QuickWins'); | ||
|
||
$quickWins = $quickWinsTable->find() | ||
->contain('Users') | ||
->orderBy(['QuickWins.created' => 'DESC']) | ||
->all(); | ||
|
||
$collectedUsersInMessages = []; | ||
foreach ($quickWins as $quickWin) { | ||
// extract all user ids from message: "<@U042CECCR7A> has tagged you in a message" | ||
preg_match_all('/<@([A-Z0-9]+)>/', $quickWin->message, $matches); | ||
foreach ($matches[1] as $match) { | ||
$collectedUsersInMessages[] = $match; | ||
} | ||
} | ||
|
||
$collectedUsersInMessages = array_unique($collectedUsersInMessages); | ||
|
||
$usersTable = $this->fetchTable('Users'); | ||
$users = $usersTable->find() | ||
->where([ | ||
'slack_user_id IN' => !empty($collectedUsersInMessages) ? | ||
$collectedUsersInMessages : [null], | ||
]) | ||
->all(); | ||
|
||
foreach ($quickWins as $quickWin) { | ||
foreach ($users as $user) { | ||
// replace all user ids with user names | ||
$quickWin->message = str_replace( | ||
"<@{$user->slack_user_id}>", | ||
"<@{$user->slack_name}>", | ||
$quickWin->message | ||
); | ||
} | ||
} | ||
|
||
return $this->response | ||
->withStatus(200) | ||
->withType('json') | ||
->withStringBody(json_encode($quickWins)); | ||
} | ||
} |
Oops, something went wrong.