Skip to content

Commit

Permalink
fix migrate bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
nodeloc committed Sep 23, 2024
1 parent 0cff410 commit 5663935
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 80 deletions.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
}
],
"require": {
"flarum/core": "^1.3.0"
"flarum/core": "^1.3.0",
"antoinefr/flarum-ext-money": "^1.3.0",
"mattoid/flarum-ext-money-history": "^1.1.1"
},
"authors": [
{
Expand Down
2 changes: 1 addition & 1 deletion js/dist/forum.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/dist/forum.js.map

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions js/src/forum/components/EventCountDown.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ export default class EventCountDown extends Component {
vnode.state.hours = Stream();
vnode.state.minutes = Stream();
vnode.state.seconds = Stream();
this.uniqueId = 'clockdiv-' + vnode.attrs.id; // Use the provided id
}
oncreate(vnode) {
var deadline = vnode.attrs.endDate;


function time_remaining(endtime) {
var t = Date.parse(endtime) - Date.parse(new Date());
var seconds = Math.floor((t / 1000) % 60);
Expand All @@ -30,7 +32,7 @@ export default class EventCountDown extends Component {
var minutes_span = clock.querySelector('.minutes');
var seconds_span = clock.querySelector('.seconds');

function update_clock() {
function update_clock(id) {
var t = time_remaining(deadline);
days_span.innerHTML = t.days;
hours_span.innerHTML = ('0' + t.hours).slice(-2);
Expand All @@ -43,15 +45,15 @@ export default class EventCountDown extends Component {
elem.parentNode.removeChild(elem);
}
var finishText = app.translator.trans('nodeloc-lottery.forum.endDateText');
var finishDiv = document.getElementById('clockdiv');
var finishDiv = document.getElementById(id);
finishDiv.innerHTML = '<h1 class="letterpress">' + finishText + '</h1>';
}
}

update_clock();
var timeinterval = setInterval(() => update_clock(), 1000);
update_clock(id);
var timeinterval = setInterval(() => update_clock(id), 1000);
}
run_clock('clockdiv', deadline);
run_clock(this.uniqueId, deadline);

}
view(vnode) {
Expand All @@ -65,7 +67,7 @@ export default class EventCountDown extends Component {
return (
<div class="countdown-container">
<h2 class="event-text" id="titleEvent"><i class={fontAwIcon + " " + 'fontawicon'}></i>{wgEvents}</h2>
<div id="clockdiv">
<div class="clockdiv" id={this.uniqueId}>
<div class="cntdwn-widget">
<span class="days">{vnode.state.days()}</span>
<div class="smalltext">{wgDays}</div>
Expand Down
2 changes: 1 addition & 1 deletion js/src/forum/components/ListLotteryModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class ListLotteryModal extends Modal {
super.oninit(vnode);
this.loading = Stream(true);
app.store
.find('nodeloc/lottery', this.attrs.lottery.id(), {
.find('nodeloc/lottery', this.attrs.lottery.data.id, {
include: 'participants,participants.user,participants.status',
})
.then(() => this.loading(false))
Expand Down
6 changes: 3 additions & 3 deletions js/src/forum/components/PostLottery.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default class PostLottery extends Component {
const endDate = dayjs(lottery.endDate());
const hasEntered = lottery.lottery_participants()?.length > 0;
return (
<div className="Post-lottery" data-id={lottery.id()}>
<div className="Post-lottery" data-id={lottery.data.id}>
<div className="LotteryHeading">
<h3 className="LotteryHeading-title">{lottery.prizes()}</h3>
<Tooltip text={app.translator.trans('nodeloc-lottery.forum.public_lottery')}>
Expand Down Expand Up @@ -64,7 +64,7 @@ export default class PostLottery extends Component {
{lottery.max_participants()<9999 &&(<>
<span class='min_participants'>{app.translator.trans('nodeloc-lottery.forum.modal.max_participants')}</span><span>{lottery.max_participants()}</span></>)}
</div>
<EventCountDown endDate={endDate} />
<EventCountDown id={lottery.data.id} endDate={endDate} />
</div>
<div className="LotteryOptions">
{
Expand Down Expand Up @@ -171,7 +171,7 @@ export default class PostLottery extends Component {
return app
.request({
method: 'PATCH',
url: `${app.forum.attribute('apiUrl')}/nodeloc/lottery/${this.attrs.lottery.id()}/enter`,
url: `${app.forum.attribute('apiUrl')}/nodeloc/lottery/${this.attrs.lottery.data.id}/enter`,
})
.then((res) => {
app.store.pushPayload(res);
Expand Down
34 changes: 14 additions & 20 deletions migrations/2024_01_31_000000_add_lotteries_table.php
Original file line number Diff line number Diff line change
@@ -1,34 +1,28 @@
<?php

/*
* This file is part of nodeloc/lottery.
*
* Copyright (c) Nodeloc.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use Flarum\Database\Migration;
use Illuminate\Database\Schema\Blueprint;

return Migration::createTable('lotteries', function (Blueprint $table) {
$table->increments('id');

$table->string('question');

$table->string('prizes')->comment('奖品');
$table->integer('price')->nullable()->comment('参与价格');
$table->integer('amount')->comment('数量');
$table->timestamp('end_date')->nullable()->comment('开奖日期');
$table->integer('post_id')->unsigned();
$table->integer('user_id')->unsigned()->nullable();
$table->integer('vote_count')->unsigned();
$table->integer('max_votes')->unsigned();

$table->boolean('allow_multiple_votes');


$table->boolean('public_lottery');
$table->integer('min_participants')->unsigned()->comment('最少人数');
$table->integer('max_participants')->unsigned()->comment('最多人数');
$table->integer('enter_count')->default(0);
$table->boolean('can_cancel_enter')->nullable();
$table->tinyInteger('status')->comment('0:已发布 1:已开奖 2:到期人数不够取消');
$table->json('settings');
$table->timestamp('end_date')->nullable();
$table->timestamps();

$table->primary('id');
$table->index('user_id');
$table->index('post_id');

$table->foreign('post_id')->references('id')->on('posts')->onDelete('cascade');
$table->foreign('user_id')->references('id')->on('users')->onDelete('set null');
});
27 changes: 10 additions & 17 deletions migrations/2024_01_31_000001_add_lottery_options_table.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
<?php

/*
* This file is part of nodeloc/lottery.
*
* Copyright (c) Nodeloc.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use Flarum\Database\Migration;
use Illuminate\Database\Schema\Blueprint;

return Migration::createTable('lottery_options', function (Blueprint $table) {
$table->increments('id');

$table->string('answer');

$table->integer('lottery_id')->unsigned();
$table->integer('vote_count')->unsigned();
$table->string('image_url');

$table->string('operator_type', 256)->comment('运算类型');
$table->unsignedInteger('lottery_id');
$table->unsignedTinyInteger('operator')->comment('0 等于 1 小于等于 2 大于等于');
$table->integer('operator_value')->comment('数值');
$table->timestamps();

$table->foreign('lottery_id')->references('id')->on('lotteries')->onDelete('cascade');
$table->index('lottery_id');

$table->foreign('lottery_id')
->references('id')
->on('lotteries')
->onDelete('cascade');
});
25 changes: 25 additions & 0 deletions migrations/2024_01_31_000002_add_lottery_participants_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

use Flarum\Database\Migration;
use Illuminate\Database\Schema\Blueprint;

return Migration::createTable('lottery_participants', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('lottery_id');
$table->unsignedTinyInteger('status')->comment('0 未中奖 1中奖');
$table->unsignedInteger('user_id')->nullable();
$table->timestamps();

$table->index('lottery_id');
$table->index('user_id');

$table->foreign('lottery_id')
->references('id')
->on('lotteries')
->onDelete('cascade');

$table->foreign('user_id')
->references('id')
->on('users')
->onDelete('set null');
});
27 changes: 0 additions & 27 deletions migrations/2024_01_31_000002_add_lottery_votes_table.php

This file was deleted.

6 changes: 3 additions & 3 deletions resources/less/forum.less
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

.countdown-container {
opacity: 0.68;
#clockdiv {
.clockdiv {
font-family: Helvetica, sans-serif ;
color: #fff;
display: inline-block;
Expand All @@ -40,12 +40,12 @@
}


#clockdiv > div {
.clockdiv > div {
padding: 10px;
display: inline-block;
}

#clockdiv div > span {
.clockdiv div > span {
padding: 15px;
border-radius: 3px;
background: #333;
Expand Down

0 comments on commit 5663935

Please sign in to comment.