Debian Codegraph @

resources/src/mediawiki.special.block/components/TargetActiveBlocks.vue

raw
1 <template>
2 <cdx-accordion>
3 <template #title>
4 {{ $i18n( 'block-user-active-blocks' ).text() }}
5 </template>
6 <cdx-table
7 class="mw-block-active-blocks"
8 :caption="$i18n( 'block-user-active-blocks' ).text()"
9 :columns="columns"
10 :data="data"
11 :use-row-headers="true"
12 :hide-caption="true"
13 >
14 <template #empty-state>
15 {{ $i18n( 'block-user-no-previous-blocks' ).text() }}
16 </template>
17 <template #item-timestamp="{ item }">
18 {{ util.formatTimestamp( item ) }}
19 </template>
20 <template #item-target="{ item }">
21 <!-- TODO: Is this safe? -->
22 <!-- eslint-disable-next-line vue/no-v-html -->
23 <span v-html="$i18n( 'userlink-with-contribs', item ).parse()"></span>
24 </template>
25 <template #item-expires="{ item }">
26 {{ util.formatTimestamp( item ) }}
27 </template>
28 <template #item-blockedby="{ item }">
29 <!-- TODO: Is this safe? -->
30 <!-- eslint-disable-next-line vue/no-v-html -->
31 <span v-html="$i18n( 'userlink-with-contribs', item ).parse()"></span>
32 </template>
33 <template #item-parameters="{ item }">
34 <ul>
35 <li v-for="( parameter, index ) in item" :key="index">
36 {{ util.getBlockFlagMessage( parameter ) }}
37 </li>
38 </ul>
39 </template>
40 <template #item-reason="{ item }">
41 {{ item ? item : $i18n( 'block-user-no-reason-given' ).text() }}
42 </template>
43 </cdx-table>
44 </cdx-accordion>
45 </template>
46
47 <script>
48 const util = require( '../util.js' );
49 const { defineComponent } = require( 'vue' );
50 const { CdxAccordion, CdxTable } = require( '@wikimedia/codex' );
51
52 // @vue/component
53 module.exports = defineComponent( {
54 name: 'TargetActiveBlocks',
55 components: { CdxAccordion, CdxTable },
56 props: {
57 targetUser: {
58 type: [ Number, String, null ],
59 required: true
60 }
61 },
62 setup() {
63 const columns = [
64 { id: 'timestamp', label: mw.message( 'blocklist-timestamp' ).text(), minWidth: '112px' },
65 { id: 'target', label: mw.message( 'blocklist-target' ).text(), minWidth: '200px' },
66 { id: 'expires', label: mw.message( 'blocklist-expiry' ).text(), minWidth: '112px' },
67 { id: 'blockedby', label: mw.message( 'blocklist-by' ).text(), minWidth: '200px' },
68 { id: 'parameters', label: mw.message( 'blocklist-params' ).text(), minWidth: '160px' },
69 { id: 'reason', label: mw.message( 'blocklist-reason' ).text(), minWidth: '160px' }
70 ];
71
72 return {
73 columns,
74 util
75 };
76 },
77 data() {
78 return {
79 data: []
80 };
81 },
82 methods: {
83 getUserBlocks( searchTerm ) {
84 const api = new mw.Api();
85
86 const params = {
87 origin: '*',
88 action: 'query',
89 format: 'json',
90 formatversion: 2,
91 list: 'blocks',
92 aulimit: '10',
93 bkprop: 'id|user|by|timestamp|expiry|reason|range|flags',
94 bkusers: searchTerm
95 };
96
97 return api.get( params )
98 .then( ( response ) => response.query );
99 }
100 },
101 watch: {
102 targetUser: {
103 handler( newValue ) {
104 if ( newValue ) {
105 this.data = [];
106 // Look up the current block(s) for the target user
107 this.getUserBlocks( newValue ).then( ( data ) => {
108 for ( let i = 0; i < data.blocks.length; i++ ) {
109 this.data.push( {
110 timestamp: data.blocks[ i ].timestamp,
111 target: data.blocks[ i ].user,
112 expires: data.blocks[ i ].expiry,
113 blockedby: data.blocks[ i ].by,
114 // parameters: data.blocks[ i ].range,
115 reason: data.blocks[ i ].reason
116 } );
117 }
118 } );
119 }
120 },
121 immediate: true
122 }
123 }
124 } );
125 </script>
126
127 <style lang="less">
128 @import 'mediawiki.skin.variables.less';
129
130 .mw-block-active-blocks {
131 word-break: auto-phrase;
132 }
133 </style>