Compare commits
	
		
			1 commit
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 647faa3c03 | 
					 4 changed files with 27 additions and 9 deletions
				
			
		|  | @ -1,5 +1,6 @@ | ||||||
| <template> | <template> | ||||||
| <div class="mk-poll-editor"> | <div class="mk-poll-editor"> | ||||||
|  | 	<ui-input type="date"></ui-input> | ||||||
| 	<p class="caution" v-if="choices.length < 2"> | 	<p class="caution" v-if="choices.length < 2"> | ||||||
| 		<fa icon="exclamation-triangle"/>{{ $t('no-only-one-choice') }} | 		<fa icon="exclamation-triangle"/>{{ $t('no-only-one-choice') }} | ||||||
| 	</p> | 	</p> | ||||||
|  | @ -72,6 +73,8 @@ export default Vue.extend({ | ||||||
| <style lang="stylus" scoped> | <style lang="stylus" scoped> | ||||||
| .mk-poll-editor | .mk-poll-editor | ||||||
| 	padding 8px | 	padding 8px | ||||||
|  | 	max-height 300px | ||||||
|  | 	overflow auto | ||||||
| 
 | 
 | ||||||
| 	> .caution | 	> .caution | ||||||
| 		margin 0 0 8px 0 | 		margin 0 0 8px 0 | ||||||
|  |  | ||||||
|  | @ -39,6 +39,7 @@ export type INote = { | ||||||
| 	replyId: mongo.ObjectID; | 	replyId: mongo.ObjectID; | ||||||
| 	renoteId: mongo.ObjectID; | 	renoteId: mongo.ObjectID; | ||||||
| 	poll: { | 	poll: { | ||||||
|  | 		period: Date; | ||||||
| 		choices: Array<{ | 		choices: Array<{ | ||||||
| 			id: number; | 			id: number; | ||||||
| 		}> | 		}> | ||||||
|  |  | ||||||
|  | @ -133,10 +133,10 @@ export const meta = { | ||||||
| 
 | 
 | ||||||
| 		poll: { | 		poll: { | ||||||
| 			validator: $.obj({ | 			validator: $.obj({ | ||||||
| 				choices: $.arr($.str) | 				period: $.num.optional.nullable, | ||||||
|  | 				choices: $.arr($.str.range(0, 50)) | ||||||
| 					.unique() | 					.unique() | ||||||
| 					.range(2, 10) | 					.range(2, 10) | ||||||
| 					.each(c => c.length > 0 && c.length < 50) |  | ||||||
| 			}).optional.strict(), | 			}).optional.strict(), | ||||||
| 			desc: { | 			desc: { | ||||||
| 				'ja-JP': 'アンケート' | 				'ja-JP': 'アンケート' | ||||||
|  | @ -210,16 +210,26 @@ export default define(meta, (ps, user, app) => new Promise(async (res, rej) => { | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	let poll: INote['poll']; | ||||||
|  | 
 | ||||||
| 	if (ps.poll) { | 	if (ps.poll) { | ||||||
| 		(ps.poll as any).choices = (ps.poll as any).choices.map((choice: string, i: number) => ({ | 		const now = new Date(); | ||||||
| 			id: i, // IDを付与
 | 		if (ps.poll.period && (ps.poll.period <= now.getTime())) { | ||||||
| 			text: choice.trim(), | 			return rej('invalid poll period range'); | ||||||
| 			votes: 0 | 		} | ||||||
| 		})); | 
 | ||||||
|  | 		poll = { | ||||||
|  | 			period: ps.poll.period ? new Date(ps.poll.period) : null, | ||||||
|  | 			choices: ps.poll.choices.map((choice: string, i: number) => ({ | ||||||
|  | 				id: i, // IDを付与
 | ||||||
|  | 				text: choice.trim(), | ||||||
|  | 				votes: 0 | ||||||
|  | 			})) | ||||||
|  | 		}; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// テキストが無いかつ添付ファイルが無いかつRenoteも無いかつ投票も無かったらエラー
 | 	// テキストが無いかつ添付ファイルが無いかつRenoteも無いかつ投票も無かったらエラー
 | ||||||
| 	if (!(ps.text || files.length || renote || ps.poll)) { | 	if (!(ps.text || files.length || renote || poll)) { | ||||||
| 		return rej('text, fileIds, renoteId or poll is required'); | 		return rej('text, fileIds, renoteId or poll is required'); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -227,7 +237,7 @@ export default define(meta, (ps, user, app) => new Promise(async (res, rej) => { | ||||||
| 	create(user, { | 	create(user, { | ||||||
| 		createdAt: new Date(), | 		createdAt: new Date(), | ||||||
| 		files: files, | 		files: files, | ||||||
| 		poll: ps.poll, | 		poll: poll, | ||||||
| 		text: ps.text, | 		text: ps.text, | ||||||
| 		reply, | 		reply, | ||||||
| 		renote, | 		renote, | ||||||
|  |  | ||||||
|  | @ -59,6 +59,10 @@ export default define(meta, (ps, user) => new Promise(async (res, rej) => { | ||||||
| 		return rej('already voted'); | 		return rej('already voted'); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	if (note.poll.period && (note.poll.period.getTime() - Date.now() < 0)) { | ||||||
|  | 		return rej('poll period expired'); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	// Create vote
 | 	// Create vote
 | ||||||
| 	await Vote.insert({ | 	await Vote.insert({ | ||||||
| 		createdAt: new Date(), | 		createdAt: new Date(), | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue