mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
feat(admin): consecutive months editable field and automatic calcs
This commit is contained in:
@@ -22,11 +22,6 @@
|
|||||||
Account created:
|
Account created:
|
||||||
<strong>{{ hero.auth.timestamps.created | formatDate }}</strong>
|
<strong>{{ hero.auth.timestamps.created | formatDate }}</strong>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
|
||||||
Most recent cron:
|
|
||||||
<strong>{{ hero.auth.timestamps.loggedin | formatDate }}</strong>
|
|
||||||
("auth.timestamps.loggedin")
|
|
||||||
</div>
|
|
||||||
<div v-if="cronError">
|
<div v-if="cronError">
|
||||||
"lastCron" value:
|
"lastCron" value:
|
||||||
<strong>{{ hero.lastCron | formatDate }}</strong>
|
<strong>{{ hero.lastCron | formatDate }}</strong>
|
||||||
@@ -36,12 +31,19 @@
|
|||||||
("auth.timestamps.loggedin" and "lastCron" dates are different).
|
("auth.timestamps.loggedin" and "lastCron" dates are different).
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-inline">
|
||||||
|
<div>
|
||||||
|
Most recent cron:
|
||||||
|
<strong>{{ hero.auth.timestamps.loggedin | formatDate }}</strong>
|
||||||
|
("auth.timestamps.loggedin")
|
||||||
|
</div>
|
||||||
<button
|
<button
|
||||||
class="btn btn-primary"
|
class="btn btn-primary ml-2"
|
||||||
@click="resetCron()"
|
@click="resetCron()"
|
||||||
>
|
>
|
||||||
Reset Cron to Yesterday
|
Reset Cron to Yesterday
|
||||||
</button>
|
</button>
|
||||||
|
</div>
|
||||||
<div class="subsection-start">
|
<div class="subsection-start">
|
||||||
Time zone:
|
Time zone:
|
||||||
<strong>{{ hero.preferences.timezoneOffset | formatTimeZone }}</strong>
|
<strong>{{ hero.preferences.timezoneOffset | formatTimeZone }}</strong>
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
Subscription, Monthly Perks
|
Subscription, Monthly Perks
|
||||||
</h3>
|
</h3>
|
||||||
<div v-if="expand">
|
<div v-if="expand">
|
||||||
<form @submit.prevent="saveHero({hero, msg: 'Subscription Perks'})">
|
<form @submit.prevent="saveSubscriptionData()">
|
||||||
<div v-if="hero.purchased.plan.paymentMethod">
|
<div v-if="hero.purchased.plan.paymentMethod">
|
||||||
Payment method:
|
Payment method:
|
||||||
<strong>{{ hero.purchased.plan.paymentMethod }}</strong>
|
<strong>{{ hero.purchased.plan.paymentMethod }}</strong>
|
||||||
@@ -30,9 +30,20 @@
|
|||||||
</strong>
|
</strong>
|
||||||
<strong v-else> None </strong>
|
<strong v-else> None </strong>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div class="form-inline">
|
||||||
|
<label>
|
||||||
Consecutive months:
|
Consecutive months:
|
||||||
<strong>{{ hero.purchased.plan.consecutive.count }}</strong>
|
<input
|
||||||
|
v-model="consecutiveMonths"
|
||||||
|
class="form-control"
|
||||||
|
type="number"
|
||||||
|
min="0"
|
||||||
|
step="1"
|
||||||
|
>
|
||||||
|
</label>
|
||||||
|
<span class="small">
|
||||||
|
Updates Hourglasses and Gem cap automatically. Next Mystic Hourglass updates on save.
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
Months until renewal:
|
Months until renewal:
|
||||||
@@ -107,6 +118,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import clone from 'lodash/clone';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import saveHero from '../mixins/saveHero';
|
import saveHero from '../mixins/saveHero';
|
||||||
import { getPlanContext } from '@/../../common/script/cron';
|
import { getPlanContext } from '@/../../common/script/cron';
|
||||||
@@ -121,6 +133,8 @@ export default {
|
|||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
|
consecutiveMonths: 0,
|
||||||
|
startingHourglasses: 0,
|
||||||
expand: false,
|
expand: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@@ -131,10 +145,37 @@ export default {
|
|||||||
return currentPlanContext.nextHourglassDate.format('MMMM');
|
return currentPlanContext.nextHourglassDate.format('MMMM');
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
watch: {
|
||||||
|
consecutiveMonths () {
|
||||||
|
const startingMonths = this.hero.purchased.plan.consecutive.count;
|
||||||
|
const monthsAdded = Math.max(0, this.consecutiveMonths - startingMonths);
|
||||||
|
this.hero.purchased.plan.consecutive.gemCapExtra = Math.min(
|
||||||
|
Math.floor(this.consecutiveMonths / 3) * 5, 25,
|
||||||
|
);
|
||||||
|
if (monthsAdded >= 0) {
|
||||||
|
this.hero.purchased.plan.consecutive.trinkets = this.startingHourglasses
|
||||||
|
+ Math.floor(monthsAdded / 3);
|
||||||
|
}
|
||||||
|
if (this.hero.purchased.plan.gemsBought
|
||||||
|
> this.hero.purchased.plan.consecutive.gemCapExtra + 25) {
|
||||||
|
this.hero.purchased.plan.gemsBought = this.hero.purchased.plan.consecutive.gemCapExtra + 25;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
mounted () {
|
||||||
|
this.consecutiveMonths = clone(this.hero.purchased.plan.consecutive.count);
|
||||||
|
this.startingHourglasses = clone(this.hero.purchased.plan.consecutive.trinkets);
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
dateFormat (date) {
|
dateFormat (date) {
|
||||||
return moment(date).format('YYYY/MM/DD');
|
return moment(date).format('YYYY/MM/DD');
|
||||||
},
|
},
|
||||||
|
saveSubscriptionData () {
|
||||||
|
if (this.consecutiveMonths !== this.hero.purchased.plan.consecutive.count) {
|
||||||
|
this.hero.purchased.plan.consecutive.count = this.consecutiveMonths;
|
||||||
|
}
|
||||||
|
this.saveHero({ hero: this.hero, msg: 'Subscription Perks' });
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -277,9 +277,14 @@ api.updateHero = {
|
|||||||
if (updateData.purchased.plan.gemsBought) {
|
if (updateData.purchased.plan.gemsBought) {
|
||||||
hero.purchased.plan.gemsBought = updateData.purchased.plan.gemsBought;
|
hero.purchased.plan.gemsBought = updateData.purchased.plan.gemsBought;
|
||||||
}
|
}
|
||||||
if (updateData.purchased.plan.consecutive && updateData.purchased.plan.consecutive.trinkets) {
|
if (updateData.purchased.plan.consecutive) {
|
||||||
|
if (updateData.purchased.plan.consecutive.trinkets) {
|
||||||
hero.purchased.plan.consecutive.trinkets = updateData.purchased.plan.consecutive.trinkets;
|
hero.purchased.plan.consecutive.trinkets = updateData.purchased.plan.consecutive.trinkets;
|
||||||
}
|
}
|
||||||
|
if (updateData.purchased.plan.consecutive.gemCapExtra) {
|
||||||
|
hero.purchased.plan.consecutive.gemCapExtra = updateData.purchased.plan.consecutive.gemCapExtra; // eslint-disable-line max-len
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// give them gems if they got an higher level
|
// give them gems if they got an higher level
|
||||||
|
|||||||
Reference in New Issue
Block a user